Archives: JSON

Java – Convert Map to JSON

Output:

json = {“WHITE”:”#FFFFFF”,”BLUE”:”#0000FF”,”YELLOW”:”#FFFF00″,”GREEN”:”#008000″,”BLACK”:”#000000″,”RED”:”#FF0000″}
map.get = #FFFFFF
map.get = #0000FF
map.get = #FFFF00
map.get = #008000
map.get = #000000
map.get = #FF0000

Java – Convert JSON to MongoDB Object

JSON Data to Convert:

{
‘name’ : ‘javac’,
‘age’ : 6
}

Conversion Code:

Output:

{ “_id” : { “$oid” : “4dc9ebb5237f275c2fe4959f”} , “name” : “javac” , “age” : 6}
Done

Java – Read JSON Data Simple Example

In below example, it uses JSONParser to read and display JSON data from a file named “test.json“ using JSON.simple, a simple Java library for JSON processing.

Output:

prasanna
25
msg 1
msg 2
msg 3