ignore json within json - java

I am parsing a JSON document using Java Jackson library. I have a situation in which the JSON document can contain a payload field in JSON/yaml/csv format. The parser is throwing exceptions; so I don't want the payload to be parsed. Is there a way I can delimit the payload so that it is considered as a string than structure?
Following is the json document: { "recordId":"48", "payLoad":{"firstName":"John","lastName":"Doe"} }
How can I delimit the payload content to be view as a String?

Related

Best way to parse TLV data to JSON in java

I need to parse the TLV data to JSON format.
Is there any library or any best way to parse/convert it to JSON?
Note: TLV --> Tag:length:value
Sample TLV:
ID;4;1578;NAME;7;TESTING;DESCRIPTION;10;Sample TLV;
Expected output:
{
ID:"1578",
NAME:"TESTING",
DESCRIPTION:"Sample TLV"
}

Storing a JSON payload in ByteBuffer is unable to print braces or colon

I have a JSON payload encoded to Base64 that needs to be stored in a ByteBuffer to be returned.
Upon trying to convert it from Base64 to JSON on base64decode.org I am able to get the proper json but on trying to do the same in code, it just prints out the data but not the {, } or the :
I am using DatatypeConverter.parseBase64Binary to achieve it.
What should I use in the code to return the properly formatted JSON payload?

Read multipile JSON objects from single file with Jackson

I'm using Jackson 2.6.5.
I'm trying to read the following JSON:
{
"metadata1":"value",
"metadata2":"value"
}
{
"field1":"value",
"field2":"value",
....
}
With the following code:
JSONObject jsonObj = new JSONObject(jsonString);
But jsonObj contains only the "first" part of my JSON (the metadata), How can I read the "second" part of my JSON? (the part with the fields)?
EDIT
I know that my JSON doesn't contain "," so how can I parse it without "," between the jsons?
Seems like the JSON you added is missing a , sign between the two objects.
If you get such an non-json as input string, you might want to consider to:
First manipulate the input string by adding it the missing , . E.g. find the location of }{ and replace it with },{
And only then to insert it to the jackson
Your json is invalid, so you can't parse invalid json scheme by json parsing tools out of the box,
Instead you could read file by yourself into 2 strings - one valid json per string and then parse it with any json parser.

Json parser without json library

I need to make a json parser without json library. The input will be like {:[{}, {}]}. It should return 1 if string is ok and -1 if string is wrong.

Escape character in JSON parsing with org.json.JSONObject;

I am using org.json to parse and write json. While serializing, i.e converting to string, I see json object adds an extra escape character. How can be this be avoided, if possible ?
String jsonStr = "{\"AD\":\"</p>\"}";
JSONObject jsonObject = new JSONObject(jsonStr);
System.out.println(jsonStr);
System.out.println(jsonObject.toString());
Output:
{"AD":"</p>"}
{"AD":"<\/p>"}
A number of other StackOverflow posts point out that this happens because (1) it is allowed by the JSON spec, and (2) it allows the JSON string to be inserted as-is into certain XML/HTML contexts that would otherwise not allow strings with "</" inside them.
If this causes problems, I would seek out A Better Java JSON Library--one that lets you define more character-escaping options.

Categories