Package de.stefanfrings.utils
Class JsonSlurper
java.lang.Object
de.stefanfrings.utils.JsonSlurper
Parse JSON documents of any structure into a flat map key/value pairs.
Example input:
{
"name":"stefan",
"hobbies":["electronics","swimming"],
"info":{
"job":"developer",
"age":40
}
}
Example result:
- name = "stefan"
- hobbies = "electronics"
- hobbies0 = "electronics"
- hobbies1 = "swimming"
- info.job = "developer"
- info.age = "40"
The elements of arrays are numbered (e.g. hobbies0, hobbies1, hobbies2, ...). In addition, the first element is also available without number suffix (e.g. hobbies).
- Author:
- Stefan Frings, http://stefanfrings.de/javautils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ConvertingHashMapParse an JSON document into a simple flat HashMap where the keys reflect the JSON structure.
-
Constructor Details
-
JsonSlurper
public JsonSlurper()
-
-
Method Details
-
parse
Parse an JSON document into a simple flat HashMap where the keys reflect the JSON structure.- Parameters:
jsonDocument- JSON document- Returns:
- Map with all collected data.
- Throws:
IOException- Should never happen
-