json « Development « Java Data Type Q&A

1. How should I escape strings in JSON?    stackoverflow.com

When creating JSON data manually, how should I escape string fields? Should I use something like Apache Commons Lang's StringEscapeUtilities.escapeHtml, StringEscapeUtilities.escapeXml, or should I use java.net.URLEncoder? The problem is that when I ...

2. Does such a JSON string builder exist?    stackoverflow.com

I'm looking to do something like the following in Java and was wondering whether such a JSON library/helper already existed out there somewhere?

SomeJsonBuilder builder = new SomeJsonBuilder();
builder.add("one", "oneValue");
builder.add("two.three", "threeValue");
String output = ...

3. Getting a diff of two JSON strings using Java code    stackoverflow.com

Can anybody suggest some Java Library or Code to get a diff of two JSON Strings?

4. What's the right way to escape a string before writing it to an Apache Commons PropertiesConfiguration?    stackoverflow.com

We have a ".properties" file that has some values persisted as JSON. I keep getting bitten by special characters, though -- the org.json.JSONObject isn't very verbose about what causes it ...

5. how to parse a JSON string into JsonNode in Jackson?    stackoverflow.com

it should be so simple, but I just cannot find it after being trying for an hour #embarrasing I need to get a JSON string e.g. {"k1":v1,"k2":v2} parsed as a JsonNode


6. What is the easiest way to parse json using gson when the element to parse is an element of a json string?    stackoverflow.com

I am using gson to parse json into java beans. For the API I am using, a large number of the json results include the result as the first property of ...

7. Reading JSon String with Gson    stackoverflow.com

I've been pursing around Google trying to figure this out, but I can't seem to do it. I have the following json string that is returned to my java applet from ...

8. Trying to get the value of an element or itself inside some element in Json returns null    stackoverflow.com

Hello Im trying to get the value of an element from a JsonObject. i'm using java with the Gson library. here is the related part of the code:

String s = "http://maps.googleapis.com/maps/api/directions/json?origin=30.065634,31.209473&destination=29.984177,31.440052&sensor=false";
URL url ...

9. How to read stringified JSON string in Java    stackoverflow.com

Kindly need your help as this really taking me long time to try. From JSP, I passed the stingnify JSON object as a String to the Java action, it like

String jsonDealer = ...

10. JSON-lib escaping / preserving strings    stackoverflow.com

I am using JSON-lib library for java http://json-lib.sourceforge.net I just want to add simple string which can look like JSON (but i do not want library to automatically figure out ...

11. Reading JSON String using JSON/Gson    stackoverflow.com

I have the JSON String of the below format which I get as a http request in Java. I need to get the name and values of the below JSON string, ...

12. Convert Json object into string in java    stackoverflow.com

I got the the Json value from server as


13. Gson - attempting to convert json string to custom object    stackoverflow.com

Here is my Json returned from the server

{"ErrorCode":1005,"Message":"Username does not exist"}
Here is my class for an error
public class ErrorModel {
public int ErrorCode;
public String Message;
and here is my conversion code.
public static ErrorModel ...

14. How to convert a String to JsonObject using gson library    stackoverflow.com

Please advice how to convert a String to JsonObject using gson library. What I unsuccesfully do:

String string = "abcde";
Gson gson = new Gson();
JsonObject json = new JsonObject();
json = gson.toJson(string); // ...

15. Can a malformed JSON string be parsed successfully?    stackoverflow.com

Here's a sample string:

String s = "{\"source\": \"another \"quote inside\" text\"}";
What's the best way to parse this? I've already tried 4 parsers: json-lib, json-simple, gson, and Grails built-in JSON parser. I'm ...

16. How to convert String to JSONObject in Java    stackoverflow.com

I have String which like this,remember it is stored in jsonString String variable..

Now I want to convert it into JSON Object. I searched more on Google but didn't get any expected ...

17. deserialize json field into plain string with gson    stackoverflow.com

I am trying to deserialize a json object into a java bean. The main issue I am facing is that I'd like to treat the field object of the json string ...

18. How to determine a match between 2 JSONs?    stackoverflow.com

I have two data sources, and both of them return JSONs. I want to ensure that there is some percentage of match (overlap of data, if you will) in the two JSONs, ...

19. Is it possible to get null from getString using JSONLib    stackoverflow.com

I'm using JSON-lib to parse an object and read a string from it. This works fine for a valid string but it can also be null. For ...

20. Json string parsing to java object with multiple objects    stackoverflow.com

Trying to parse the following json string to java object using gson

    "entry": "132456",
    "product": {
        "item": "123456",

21. Create JSON object and convert it to String in Java    stackoverflow.com

I need to send a quite long JSON header through an http post. In Python was like this:

    self.body_header = {

22. Response String to Json with Gson    stackoverflow.com

I'm writting a program in Java that makes requests to an external API by calling some methods. Each of theese methods returns a diferent JSON structure and it also depends on ...

23. How do I parse json string that contains list with gson?    stackoverflow.com

How do I parse this particular json string with Gson in Java?

What is problematic is the orders list. I suppose one has to use a "type token" parameter to Gson.parse(json,type-toke), but it ...

24. How to find specified name and its value in JSON-string from Java?    stackoverflow.com

Let's assume we have the next JSON string:

   "name" : "John",
   "age" : "20",
   "address" : "some address",
   "someobject" : {

25. java : String to JSON order changed    stackoverflow.com

import org.json.JSONObject;

public class TestFile {

    public static void main(String d[]) throws Exception{

            String ch = "{'r':1,'is':'abc'}";


26. Converting a String to json in java    stackoverflow.com

I am a newbie to using jackson library. I am trying to do this [see below], and it is throwing error.

String x="{'candidateId':'k','candEducationId':1,'activitiesSocieties':'Activities for cand1'}";
ObjectMapper mapper = new ObjectMapper();

try {

27. Can't parse JSON property "null"    stackoverflow.com

I faced with one trouble when tried to parse JSON "null" property, please help me to understand what's the real problem. I had a following JSON:

  "properties" : {  ...

28. How i can get all the keys from a string which somehow looks like json string    stackoverflow.com

I have a string like below

Can I use some java method to get all the key values (226167,3193 ) in a List object. If yes How it's ...

29. How to use JSONDeserializer to deserialize this string?    stackoverflow.com

I have string like follows:

How can I use JSONDeserializer to extract (226167,3193) from the above string object? I probably want to have a list (226167,3193,...) from the above ...

30. java: json parser problem with same strings    stackoverflow.com

I wrote this code:

private ArrayList<HashMap<String, HashMap<Integer, String>>> listContent2 = new ArrayList<HashMap<String, HashMap<Integer, String>>>();

public ArrayList<HashMap<String, HashMap<Integer, String>>> content() {
    JSONObject json = JSONfunctions.getJSONfromURL("http://...");
    try {

31. Get JSON String in java with org.json    stackoverflow.com

[{"post":{"titel":"Glee","interpret":"Bran Van 3000","jahr":"1997","id":"5"}},{"post":{"titel":"Goodbye Country (Hello Nightclub)","interpret":"Groove Armada","jahr":"2001","id":"4"}},{"post":{"titel":"Beauty","interpret":"Ryuichi Sakamoto","jahr":"1990","id":"1"}}]
The above string is what i have in json and now what i want to do is to just get the values of ...

32. How to get Java objects from JSON string    stackoverflow.com

How can I get Java objects from this JSON string? We don't have the name of the object in the JSON string


33. Error on constructing JSONArray from String    stackoverflow.com

I am trying to construct a JSONArray from a String, and extract the JSONObjects from inside it. Here is my code:

String jsonStr = "[{\"name\" : \"John Doe\",\"gender\":\"male\",\"age\":40},{\"name\" : \"Jane Doe\",\"gender\":\"female\",\"age\":30}]";

JSONArray jsonArr ...

34. Parsing a malformed jSon string    stackoverflow.com

I'm using a Java Json library to convert an incoming string into a json one. The lib is json-lib. The problem is that I can't modify the source so, sometimes I ...

35. How to create a JSON string which only contains the changed values?    stackoverflow.com

I want to minimize the amount of JSON data transferred. Let's say I have a class with 100 key/value pairs and then I change one of these and want to transfer ...

36. Java - Parsing String to JsonObject using GSON    stackoverflow.com

I have the following code:

JsonParser parser = new JsonParser();
System.out.println("gson.toJson: "  + gson.toJson(roomList));
JsonObject json2 = parser.parse("{\"b\":\"c\"}").getAsJsonObject();
System.out.println("json2: " + json2);
JsonObject json = parser.parse(gson.toJson(roomList)).getAsJsonObject();
System.out.println("json: " + json);
and it gives me the following ...

37. write json string in JAVA    stackoverflow.com

I am using json developing android sdk. I found writing json string is annoying, take a look:

I need to manually escape quotes, is there any clean way to do this?

38. How to exclude null-value fields when using Flexjson?    stackoverflow.com

I am serializing a class like this into JSON using Flexjson:

public class Item {
    private Long id;
    private String name;
    private String ...

39. Constructing POJO out of JSON string with dynamic fields using Gson    stackoverflow.com

I'm consuming a web service in my application that will return a list of ID's associated with a name. An example would look like this:

  "6502": "News",
  "6503": "Sports",

40. JSON UTF-8 enconding errors    stackoverflow.com

I have some UTF8 enconding errors using JSON in JAVA:

JSONObject json = new JSONObject();
json.put("Name", "Müller");
But I would like the following:
Any suggestions? Stromsam

41. Json string feilds and values to be listed for putting them in a table    stackoverflow.com

  "statusCode": 1,
  "statusMessage": "Success",
  "meetingResults": {
  "meetingSearchResult": [
    "meetingID": [

42. Jackson Deserialize Variable as Json String    stackoverflow.com

I have a model like that:

private String message;
private Integer errorCode;    
private String data;
I get a JSON String from remote and message, errorCode variables gets the correct value. However ...

43. Java Representation of JSON String    coderanch.com

I'm trying to create a transport object in Java for a json string. I'm using jqGrid which is a jquery plugin and it accepts a json string representing the data in the table. Up to now I've hand coded the bits to take the data I need and construct the json String. I need to create a JavaBean that I can ...

44. How to efficiently parse JSON string?    coderanch.com

45. How to read/output a JSON as a normal String variable    java-forums.org

Could someone please tell me how to convert JSON to a String variable so I can read it. At the moment, my code is like this: URL urban = new URL("http://www.urbandictionary.com/iphone/search/define?term=jad"); URLConnection yc = urban.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); int index_of = in.readLine().indexOf("n\":"); // dont worry about this line System.out.println("index: "+index_of); //dont worry bout this String output= in.readLine().toString(); System.out.println("Sentence ...

46. looping through json object in a query string    forums.oracle.com

47. Parse JSON string    forums.oracle.com