I have an XML with the attribute <name.first>.
I want to convert this XML to JSON and save it to MongoDB.
I am using org.json.XML to convert it to JSONObject with:
XML.toJSONObject(xml)
The converted JSON contains the key: { ... , name.first : ... }, which is not supported with MongoDB.
Is there a way to serialize the XML converter so that the conversion would output something else like name_first ?
Related
I saved a json into the database as a string like this:
"[_district:_1_2_5village, _name:_1_1_2id_inter, _gender:_1_3_5sex]"
Now i want to convert it back to a Json Object so as to pick the key and value eg _district is the key and _1_2_5village is the value. Any help on how i can achieve this. Thanks
I tried to convert the string back into JSON by parsing but that dint work for me.
It doesn't work because that's not a JSON format, a JSON is a way of mapping objects and uses key value syntax like so:
{"key": "value"}
and an array would look like this:
[{"key": "value"},{"key": "value"}]
You'll need to make a custom parser for your syntax
Here's the json specification:
https://www.json.org/json-en.html
I am getting a JSON in below format:
{
"A":"1",
"B":"2"
}
I have a field update and JSON at some point could be too long.
How can I change the JSON format to below pattern?
{"A":"1","B":"2"}
I am trying to store this minified JSON format on a field, so that char limit issue is resolved.
deserialize the string and serialize it again and then update the field.
Declare the JSON as string
Map<String,Object> parser = (Map<String,Object>)JSON.deserializeUntyped(yourstring);
yourstring = JSON.serialize(parser);
You can change Map accordingly. Required format will be present in string variable.
I have JSON as string
"{nameBitsCount=131}"
I need, using Jackson: 1) Parse this JSON correctly. 2) Put result into Map<String, Long>
But I Getting exception.
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('n' (code 110)): was expecting double-quote to start field name
at [Source: (String)"{nameBitsCount=131}";
PS: I think I need to change style of JSON to this
"{\"nameBitsCount\":\"131\"}";
The JSON you send isn't valid
{nameBitsCount=131}
need to convert format :
{"nameBitsCount":131}
add {"} around the Key and change {=} to {:} the JSON format valid for Json Object :
{
"Key" : "Value"
// "VALUE" if use for String and char put {"} around the value VALUE ex: 0.0 , 1 , -50 , FALSE
}
Look this website :
JSON Website
JSON Syntax
I have a string that looks like this..
"Message" : "{\"eventType\":\"DataChanged\",\"operation\":\"create\"}"
Is there any library in Java that can convert this to the string below so I can then parse it into a json object
"Message" : {"eventType":"DataChanged","operation":"create"}
I'm trying to convert an xml to json data using the java-json.jar . The conversion is done. but have issues with the resulting JSON data like
An Integer is expected but the data is converted as String.
it would not create a list if there was only one child element ( even when it should be a list as per the JSON schema ).
Is there any way to convert XML into JSON based on the JSON schema in Java?