Package groovy.json
Class JsonSlurper
- java.lang.Object
-
- groovy.json.JsonSlurper
-
public class JsonSlurper extends java.lang.Object
JSON slurper which parses text or reader content into a data structure of lists and maps.Example usage:
def slurper = new JsonSlurper() def result = slurper.parseText('{"person":{"name":"Guillaume","age":33,"pets":["dog","cat"]}}') assert result.person.name == "Guillaume" assert result.person.age == 33 assert result.person.pets.size() == 2 assert result.person.pets[0] == "dog" assert result.person.pets[1] == "cat"
- Since:
- 1.8.0
- Author:
- Guillaume Laforge
-
-
Constructor Summary
Constructors Constructor Description JsonSlurper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
parse(java.io.Reader reader)
Parse a JSON data structure from content from a readerjava.lang.Object
parseText(java.lang.String text)
Parse a text representation of a JSON data structure
-
-
-
Method Detail
-
parseText
public java.lang.Object parseText(java.lang.String text)
Parse a text representation of a JSON data structure- Parameters:
text
- JSON text to parse- Returns:
- a data structure of lists and maps
-
parse
public java.lang.Object parse(java.io.Reader reader)
Parse a JSON data structure from content from a reader- Parameters:
reader
- reader over a JSON content- Returns:
- a data structure of lists and maps
-
-