change incorrect data into valid JSON

I am encountering an issue with a JSON file that contains illegal characters

{"message":"A"B",
  "fromWhom":"53"}

My goal is to extract plain text sent from the server spring to the client in order for the client to receive the full data.

Is there a way to replace illegal characters within a string with a valid JSON object?

Answer №1

Here's a valid response:

{
"content": "X Y",
"sender": "33"
}

Are you wondering why there is a floating quotation mark included?

Additionally, I recommend using this helpful resource for validating JSON data.

http://jsonlint.com/

I trust that this addresses your query.

UPDATE:

If you absolutely need to utilize the double quote, it can be escaped as demonstrated below in order to remain valid.

{
"content": "A\"B",
"sender": "33"
}

Answer №2

It seems that escaping the quote is necessary in this case.

    {
    "message": "A\"B",
    "fromWhom": "53"
    }

To change the value, using JSON.parse might be the solution.

For example:

<script>
var text = '{"employees":[' +
'{"firstName":"John","lastName":"Doe" },' +
'{"firstName":"Anna","lastName":"Smith" },' +
'{"firstName":"Peter","lastName":"Jones" }]}';

obj = JSON.parse(text);
obj.employees[1].lastName = "Timmy" //Value change here
document.getElementById("demo").innerHTML =
obj.employees[1].firstName + " " + obj.employees[1].lastName;
</script>

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

Creating a regular expression for Spring's MVC url pattern

I am in need of a solution that allows me to convert a list of Spring MVC URL pattern matching expressions into Regex Patterns for string matching purposes. One example of a Spring pattern is : /actionGroups/{action-group-id:\d+} Currently, when I ...

Can users arrange a lineup of choices?

As a beginner, I have a task that seems pretty simple to others but not so much for me. I need to create a feature where a client can order 10 different services in the order they prefer. The idea is to use a dropdown menu or checkboxes to allow the user ...

The display:flex property with justify-content:space-around is malfunctioning in React and causing issues

I've been trying to troubleshoot the issue with my header, but so far I haven't found a solution. Could you please take a look at my code first? // Code simplified for clarity, no need to worry about variables const Header = () => { return ...

Creating colorful squares within a JFrame GUI interface

Can you guide me on using a GUI to create 9 different squares distributed in a grid of 3 rows and 3 columns on a frame? I want the user to be able to change the color of any square by simply right-clicking on it. A menu should then appear allowing them to ...

Trouble arises when attempting to execute a Vue method through a Vue computed property

It seems that the issue at hand is more related to general JavaScript rather than being specific to VueJS. I have a Vue Method set up to make a Firebase Call and return the requested object, which is functioning properly: methods: { getSponsor (key) { ...

Troubleshooting a Multi-dimensional Array Reference Issue

Currently, I am working with an Array and need to modify the last item by pushing it back. Below is a simplified version of the code: var array = [ [ [0,1,2], [3,4,5] ] ]; //other stuff... var add = array[0].slice(); //creat ...

verification of email address

Is there a way to execute the inverse of this code snippet? I am looking to verify whether it is false before verifying if it is true. var a = $("#phone").val(); var filter = /^[0-9]{8}$/; if(!filter.test(a)) { } else { } ...

Unraveling JSON data with PHP multi_curl: A guide to decoding JSON

As I try to retrieve data from the internet using AJAX and PHP, I encounter JSON encoded results that need decoding. Here's the PHP code snippet: $executionStartTime = microtime(true) / 1000; // Build individual requests without executing them $ch_1 ...

Scrolling seamlessly on websites with a single page

I am developing a single-page website that uses different section IDs instead of multiple pages. It's functioning properly, but I want to implement smooth scrolling to the sections rather than just statically jumping to them on the page. Jsfiddle: ht ...

Trouble with Managing Redirects Following Deletion of Blog Post in a Node.js Express Application

I've run into an issue where users are not redirected to the /blogs page after successfully deleting a blog post in my Node.js Express application. Instead, they are redirected back to the /blogs/:id, which results in an error since the post has been ...

What is the best way to build an AngularJS state parameter within the view using string concatenation?

When utilizing the AngularJD ui-router, I have set up a state called myState with three parameters: stateParam1, stateParam2, and stateParam3. In my scenario, I have already defined variables var1 and var2. I successfully pass them as stateParam1 and stat ...

update the dropdown values in the database by submitting the form

Members sign up for the website. The administrator will log in and access a list of users. I am attempting to provide an option for the admin to select a checkbox and update the user's status through a dropdown menu submission. When I tested the code ...

Configuring a JAR file for automatic use during the compilation and execution of Java applications

I currently compile and execute Selenium programs using the following command: javac -classpath .:"/Users/ravigupta/Downloads/WebDriverZen/SelSerStdAln2400.jar" WebDriverTest.java java -classpath .:"/Users/ravigupta/Downloads/WebDriverZen/SelSerStdAln240 ...

pure-react-carousel: every slide is in view

Issue I am encountering a problem where the non-active slides in my container are not being hidden properly. This results in all of the slides being visible when only one should be displayed. Additionally, some slides are rendering outside of the designate ...

JavaScript-powered server polling

What are some effective strategies for continuously refreshing data from a server using JavaScript in an application with high refresh rate requirements? The front-end is developed using jQuery, while the backend utilizes Java Spring Framework. One exampl ...

Java Implementation for Removing Nodes in an Interval Tree

I'm on the search for a reliable IntervalTree or RangeTree implementation in Java that supports deletion operations. However, I am struggling to find one that actually works when it comes to deleting nodes. Although there is a built-in IntervalTree a ...

Adjusting the height of a GAS iframe in WordPress with iframe-resizer: A step-by-step guide

I would like to embed an iframe of my Google Application Script Web into my WordPress site without the scroll bar. Refer to the image below for context. https://i.stack.imgur.com/7L6Tw.png I encountered an error message while attempting to use the iframe ...

Why is this component not functioning properly?

I am struggling with making a function to add a component dynamically when I click a button, similar to the code below. However, my attempt at creating a separate method for adding the component instead of using an inline expression is not working. Can som ...

When encountering a duplicate in the "Entry .classpath" in Gradle, an appropriate handling strategy must be specified

As I work on constructing a gradle project, an issue arises when running $ gradle build. The resulting output displays: Starting a Gradle Daemon (subsequent builds will be faster) > Task :jar FAILED FAILURE: Build failed with an exception. * What went ...

What is the most efficient way to save a document in mongoose based on a specific user's

Is there a way to ensure that when saving a template, it is associated with the user id? I have added a reference to the templateSchema for the User. User.model.js var UserSchema = new mongoose.Schema({ _id: { type: String, required: true, index: {uniq ...