Skip to content

Flip42/JsonSimple

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JsonSimple Build Status codecov


With this Library, you can easily parse a Json String to an Java Object.
All you have to do is:

JsonObject expression = JsonSimple.parse("{\"key\" : \"value\"}");
String value = expression.get("key");	//returns a String

Like this you can parse any Json String you have. In the folowing are some examples.

Parse Numbers

JsonObject expression = JsonSimple.parse("{\"int\" : 42, \"double\" : 4e-2}");
Integer theAnswer = expression.get("int");	//returns an Integer Object
Double number = expression.get("double");	//returns an Double Object

JsonSimple understands any Integer or Double Values signed or unsigned with exponent or without, try it by yourself ;)

Parse Boolean Values

JsonObject expression = JsonSimple.parse("{\"bool\" : true}");
Boolean bool = expression.get("bool");	//returns an Boolean Object

Parse Objects

JsonObject expression = JsonSimple.parse("{\"outer\":{\"inner\":\"value\"}}");
String value = ((Map)expression.get("outer")).get("inner");	//the inner Object works the same

If you parse an Object, you get a Map as the inner Object, which held all the inner values.

Parse Arrays

JsonObject expression = JsonSimple.parse("{\"array\" : [\"value\", \"value2\" ] }");
List<String> list = expression.get("array");	//returns a List

If you parse an Array, you get a List, but i think thats more kind of a improvement ;)

If you parse more complex Objects you will be returned nested Maps and Lists like above.