Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

315
Visualizações
How do I make an JSON Obfuscator? UTF 8 to UTF 16 (Js)

I'm trying to make a Unicode Converter from UTF-8 to UTF-16, but I want to only convert strings and objects and stuff like that in JSON, not the structure of JSON because that would make it unreadable to programs.

Entered UTF-8:

{
    "hi":{
        "this":["is","just","some","example"]
    }
}

Expected UTF-16:

{
    "\u0068\u0069":{
        "\u0074\u0068\u0069\u0073":["\u0069\u0073","\u006a\u0075\u0073\u0074","\u0073\u006f\u006d\u0065","\u0065\u0078\u0061\u006d\u0070\u006c\u0065"]
    }
}

Can anyone help? Also, I'm pretty new to Javascript, so don't be too harsh.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This is a pretty good way to do what you need:

let json_string = '{ "hi": {"this": ["is", "just", "some", "example"]}}'
function encode_to_utf16(x) {
  var res = "";
  for (var i = 0; i < x.length; i++) res+= "\\u" + ("000" + x[i].charCodeAt(0).toString(16)).substr(-4);
  return res;
}

// get all the values present between the double quotes
let arr = json_string.match(/"[^"]+"/gi)
arr.forEach((str)=>{
  // replace double quotes with empty string
  str = str.replace(/"/gi,"");
  // encode and replace them
  json_string = json_string.replace(str,encode_to_utf16(str))
})
console.log(json_string)

However, if there is a double quote with escape character (\") somewhere in a string, then this'll break down. Maybe, you can improvise on that.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda