Escaping strings in JSON

0 votes

How do I escape the String fields while creating the JSON data manually? I was trying to use SEU but its not escaping the quotes that is wrapping the string. Please help!

Oct 3, 2018 in Java by v.liyyah
• 1,300 points
1,211 views

1 answer to this question.

0 votes

You can find a JSON library in your language that you can feed some appropriate data structure to, and let it work for you.

In JSON the only characters you must escape are \, ", and control codes. Thus in order to escape your structure, you'll need a JSON specific function. As you might know, all of the escapes can be written as \uXXXX where XXXX is the UTF-16 code unit¹ for that character.

Hope this helps!

answered Oct 3, 2018 by geek.erkami
• 2,680 points

Related Questions In Java

0 votes
5 answers

How to compare Strings in Java?

String fooString1 = new String("foo"); String fooString2 = ...READ MORE

answered Jul 12, 2018 in Java by Daisy
• 8,110 points
306 views
0 votes
3 answers

How to parse JSON in Java

import org.json.*; JSONObject obj = new JSONObject(" .... ...READ MORE

answered Aug 20, 2018 in Java by Daisy
• 8,110 points
2,421 views
+15 votes
22 answers

How can I convert String to JSON object in Java?

Hi @Daisy You can use Google gson  for more ...READ MORE

answered Feb 7, 2019 in Java by Suresh
• 720 points
193,975 views
0 votes
1 answer

What is the concept of Immutability for strings in Java ? Why are strings immutable ?

According to Effective Java, chapter 4, page 73, ...READ MORE

answered May 11, 2018 in Java by Rishabh
• 3,580 points
428 views
0 votes
1 answer

What is the simplest way to read JSON from a URL in java

Read json from url use url.openStream() and read contents ...READ MORE

answered Jun 13, 2018 in Java by samarth295
• 2,200 points
2,238 views
0 votes
2 answers

Escape Characters in Java

These are escape characters which are used ...READ MORE

answered Oct 15, 2018 in Java by Daisy
• 8,110 points
153 views
+1 vote
10 answers

Iterate over a JSONObject?

You can use the following method to ...READ MORE

answered Dec 7, 2018 in Java by Shuvodip
58,398 views
0 votes
1 answer

Using Jackson to deserialise an array of object

First create a mapper : import com.fasterxml.jackson.databind.ObjectMapper;// in ...READ MORE

answered Sep 26, 2018 in Java by Sushmita
• 6,890 points
2,041 views
0 votes
1 answer

Sorting an ArrayList in Java

You can easily do this by simply ...READ MORE

answered May 4, 2018 in Java by geek.erkami
• 2,680 points
473 views
0 votes
1 answer

Why the main() method in Java is always static?

As you might know, static here is ...READ MORE

answered May 8, 2018 in Java by geek.erkami
• 2,680 points
747 views