Package de.stefanfrings.utils
Class JsonSlurper
- java.lang.Object
-
- de.stefanfrings.utils.JsonSlurper
-
public class JsonSlurper extends Object
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 Constructor Description JsonSlurper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ConvertingHashMap
parse(String jsonDocument)
Parse an JSON document into a simple flat HashMap where the keys reflect the JSON structure.
-
-
-
Method Detail
-
parse
public static ConvertingHashMap parse(String jsonDocument) throws IOException
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
-
-