JSON.stringify converts characters like ü, ä, ß into ├╝, ├╢, ├ñ, ├ƒ

So I have a sql file from Custom CMS that is converted into JSON. The input of the sql file contains Unicode Escape and BBCode.

I am using a script that adds keys to JSON objects by order. If the key is not in the list, it will remove it. This is the script:

let json = [
  { key1: "", key2: "", key3: "" },
  { key1: "", key2: "", key3: "" },
  { key1: "", key2: "", key3: "" },
  { key1: "", key2: "", key3: "" },
];
let startIndex = 345;
let keyList = ["ID", "key3", "key1", "key2"];
keyList.forEach((key) => {
  json.forEach((item) => {
    if (!item[key]) {
      if (key === "ID") {
        item[key] = startIndex;
        startIndex++;
      } else {
        item[key] = "";
      }
    }
  });
});
json.forEach((item) => {
  Object.keys(item).forEach((key) => {
    if (!keyList.includes(key)) {
      delete item[key];
    }
  });
});
let k = json.map((item) => {
  return JSON.parse(JSON.stringify(item, keyList, 2));
});
console.log(JSON.stringify(k));

Then whenever I make new file from this script(I use Node for running the script), the content that I have with these characters like ü, ä, ß converts them into ├╝, ├╢, ├ñ, ├ƒ.

` For example: Die weiße Rose --> Die Wei├ƒe Rose

and symbols and signs like '-', '+', '@', '$', '!' etc. `

Any help here? Thanks



Read more here: https://stackoverflow.com/questions/67380435/json-stringify-converts-characters-like-%C3%BC-%C3%A4-%C3%9F-into-%C3%B1-%C6%92

Content Attribution

This content was originally published by nikolai at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: