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

125
Visualizações
convert properties to javascript object ( bad character result)

I have some problems with characters (ä, å, ö) usually I convert them to

å=\u00e5
ä=\u00e4
ö=\u00f6

I cannot get rid of these right now because I am using an old technology Apache Wicket. my Language.proprites file looks like this

calendar-event-group-configuration=Konfigurationsgrupp f\u00f6r 
evenemang

When I am reading .properties files I get in the console ( using a npm package called ('properties-reader')) :

Konfigurationsgrupp f\\u00f6r evenemang

I expect getting:

Konfigurationsgrupp för evenemang

or

   Konfigurationsgrupp f\u00f6r evenemang

but this does happen because my code adds one more backslash to the value because of using the npm package 'properties-reader'

here is my code :

const fs = require("fs");
const PropertiesReader = require("properties-reader");
const properties = PropertiesReader("./Language_sv.properties").getAllProperties();
console.log(properties);

anyone has a better idea to get all properties in on object

Language_sv.properties is the file has :

 calendar-event-group-configuration=Konfigurationsgrupp f\u00f6r 
 evenemang

I found another package called ('properties') does not have the issue with the one above but I do not know how i can get the object (obj) out side of the function

const fs = require("fs");
var prop = require ("properties");

prop.parse ("./Language_sv.properties", { path: true }, function (error, obj){
  if (error) return console.error (error);
  
  console.log (obj);
});
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can use unescape

const property = "calendar-event-group-configuration=Konfigurationsgrupp f\u00f6r evenemang"

console.log(unescape(property));

about 4 years ago · Juan Pablo Isaza Relatório

0

Your problem is that properties-reader does not understand unicode characters. One way to go around it is to postprocess the property values after it was read.

const fs = require("fs");
const PropertiesReader = require("properties-reader");
const properties = PropertiesReader("./Language_sv.properties", 'utf-8').getAllProperties();
console.log(properties);
for(let i in properties){
    properties[i] = properties[i].split('"').join('\\"')
    properties[i] = decodeURIComponent(
        JSON.parse('"' +properties[i] + '"')
    )
}
console.log(properties);

Here I covert property value into a string enclosed within quotes, and then parse it with JSON.parse. It parses the escaped backslash properly. And decodeURIComponent coverts unicode escape sequence to the character.

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