Tips for encoding UTF characters with JSON.stringifyendcode:

Currently, I am developing a JavaScript script that is executed using windows cscript.exe. The purpose of my script is to load a JSON object from a file, add a parameter, and then save it back to the file (I am utilizing the json2.min.js implementation).

To parse the text into a JSON object, I am using JSON.parse(text), and for creating the string that is written back, I use JSON.stringify(text, null, 3). Everything works smoothly until I come across Unicode encoding.

Within the file, there are specific values such as

"someKey": "\u003Ca href=\"http://www.something.com\"\u003E"

Which after being read and saved back to the file (stringify), get changed to:

"someKey": "< a href=\"http://www.something.com\">

There are several other foreign Unicode characters that undergo conversion.

My main concern is how can I preserve the original encoding when carrying out the stringify operation?

Is there any function available for conversion that I can implement during or post stringify?

Answer №1

Avoid using JSON in binary situations since it is not binary safe.

If you require a binary-safe alternative to JSON, consider exploring BISON which provides JSON-like functionality. You can find more information about BISON at

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to customize the color of icons in react's Material-table?

I'm currently utilizing the material-table library and I'm struggling to individually change the color of each icon. Could you assist me with this? I attempted custom CSS, but it's affecting all icons at once instead of specific ones. Here i ...

Creating a process to produce a random number and send it directly to an automated email

I'm currently utilizing a form builder from jqueryform.com to construct a registration form. My goal is to have each registered user assigned with a unique account number, which will be a randomly generated 6-digit number. Additionally, I want the pro ...

Even after refreshing the page, Chrome stubbornly insists on showing the old data

I've been working on a single-page application where one page triggers server requests every time it loads. After making changes and deploying them, I noticed that the live version of the application was not reflecting the updates. Even though the cha ...

Combine two redux actions and access the modified state in the second action

I'm facing a dilemma with a straightforward problem that I believe I have a solution for, but I'm uncertain about the effectiveness of my idea. Essentially, in the current state of things, I have an array property that requires updating just bef ...

Implementing a smooth transition effect on an ajax tab

I have a tab code that uses ajax data attributes to load content. The tabs are loaded with ajax from PHP code based on the data attribute. How can I add a fade in/out effect to the tabs' content? I've attempted it but haven't been successful ...

I possess a JSON file containing a series of associative arrays that I must convert into a PHP indexed array in order to easily retrieve specific values from it

I'm struggling to convert a list of associative arrays from a JSON file into a PHP indexed array of associative arrays, and then access the values nested in those arrays. Below is the content of the JSON file: [ { "homeTeam":"tea ...

Utilizing Azure Mobile Services with HTML

Is there a way to integrate my Windows Azure Mobile Services into an HTML page? I attempted to utilize the code snippets provided in the Azure portal, but unfortunately, they did not work for me. The prescribed code snippets that need to be included in m ...

Does the organization of files and directories (such as modular programming) impact the speed at which AngularJS loads?

Can breaking code into smaller modules help decrease loading time? Exploring ways to modularize AngularJS applications can lead to a well-structured approach for developing large apps. This approach aims to streamline the development process by organizing ...

Capture audio using Node.js

Our current setup utilizes Electron to capture the voices of both the speaker (the individual using the Electron application) and the counterpart (the person on the other end of the conversation). While we can easily use "Naudiodon" to record the speaker ...

Storing a JSON object using the caching capabilities of HTML5

As an intern with minimal technical experience, I apologize if my question appears basic. I have been searching for an answer for days without much success. My current project involves developing a Phone Directory. I am now working on creating a frequentl ...

Heroku experiencing instability with Javascript/MySQL project during requests

Currently facing a problem with my Heroku API developed in JavaScript that interacts with a MySQL database. Previously operational, now encountering an error on each API request: 2020-06-17T18:37:13.493711+00:00 app[web.1]: > <a href="/cdn-cgi/l/ema ...

Uploading files with Multer and handling the JSON object

Is there a way to send both a file and a JSON object containing data using multer? I came across this thread, but it only explains how to attach one field at a time. Here's what I currently have on the client side: request .post(uploadPOSTUrl) . ...

Working with decimal numbers in jQuery and JavaScript: a basic guide

Following a button click, I have implemented a function that updates the displayed number: var initial_price = parseFloat($("#current_price").text()); var added_price = initial_price + 1.01; $("span#current_price").text(added_price); This is the ...

Saving the titles and states of checkboxes in JSON format

My approach involves storing checkboxes title and state as a JSON object with a JSONArray of JSONObject containing these values. I initially attempted to store them in two separate JSONArrays - one for titles and another for states. However, I struggled t ...

What is the best way to create a clickable link using the URL obtained from a JSON data file?

My current challenge is with printing the link from a Json data file. Specifically, I am having difficulty displaying the link from href="{{data.winnerlink}} or href="etherscan.io/tx/{{data.winner}}", despite attempting several methods. ...

AngularJS controller failing to update the angular variable

Currently diving into the world of angularjs, so any guidance would be greatly appreciated! I have been working on a basic angular application that compares two password strings in ng-controller and provides a brief message indicating if they match or not. ...

Comprehending the "fitBounds" Function in Google Maps

Just to clarify, I want to ensure that my understanding is correct. In my Google Maps app, I want to display markers from specific continents to my users. Question: Is it accurate to say that a boundary in the Google Maps API is an area defined by NO MORE ...

Pass a variable value as a parameter to a jQuery function using code-behind

Within my code behind, I am retrieving the [IDphoto] from an SQL database. My goal now is to pass this IDphoto as a parameter to a jQuery function upon onClick. How can I achieve this? Code behind sb.AppendFormat("<a onclick='popup()' href=& ...

What is the reason that the for loop updates all indexes in Node.js?

Currently, I am working on a space battle program that involves nested arrays. In order to simulate fleet fighting, I have written the following code: //Roll a dice function const randomNumber = (number) => { return Math.floor(Math.random() * numbe ...

Stop ckeditor from triggering set callback when the text is modified by an external source

Currently, I am developing a Vue project that involves the use of ckeditor5 as a text editor. Pusher, a real-time API utilizing websockets, is used to broadcast events to other Pusher instances in real time. Learn more about Pusher here. Within the ckedit ...