Package groovy.json
Class JsonSlurper
java.lang.Object
groovy.json.JsonSlurper
public class JsonSlurper
extends java.lang.Object
This has the same interface as the original JsonSlurper written for version 1.8.0, but its
 implementation has completely changed. It is now up to 20x faster than before, and its speed
 competes and often substantially exceeds popular common JSON parsers circa Jan, 2014.
 
 JSON slurper parses text or reader content into a data structure of lists and maps.
 
 Example usage:
 
 def slurper = new groovy.json.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"
 
             parser = new JsonSlurper().setType(JsonParserType.INDEX_OVERLAY);
 - Since:
- 1.8.0
- See Also:
- JsonParserType
- 
Constructor SummaryConstructors Constructor Description JsonSlurper()
- 
Method SummaryModifier and Type Method Description intgetMaxSizeForInMemory()Max size before Slurper starts to use windowing buffer parser.JsonParserTypegetType()Parser type.booleanisCheckDates()Determine if slurper will automatically parse strings it recognizes as dates.booleanisChop()Turns on buffer chopping for index overlay.booleanisLazyChop()Turns on buffer lazy chopping for index overlay.java.lang.Objectparse(byte[] bytes)Parse a JSON data structure from content from a byte array.java.lang.Objectparse(byte[] bytes, java.lang.String charset)Parse a JSON data structure from content from a byte array.java.lang.Objectparse(char[] chars)Parse a JSON data structure from content from a char array.java.lang.Objectparse(java.io.File file)Parse a JSON data structure from content within a given File.java.lang.Objectparse(java.io.File file, java.lang.String charset)Parse a JSON data structure from content within a given File.java.lang.Objectparse(java.io.InputStream inputStream)Parse a JSON data structure from content from an inputStreamjava.lang.Objectparse(java.io.InputStream inputStream, java.lang.String charset)Parse a JSON data structure from content from an inputStreamjava.lang.Objectparse(java.io.Reader reader)Parse a JSON data structure from content from a readerjava.lang.Objectparse(java.net.URL url)Parse a JSON data structure from content at a given URL.java.lang.Objectparse(java.net.URL url, java.lang.String charset)Parse a JSON data structure from content at a given URL.java.lang.Objectparse(java.net.URL url, java.util.Map params)Parse a JSON data structure from content at a given URL.java.lang.Objectparse(java.net.URL url, java.util.Map params, java.lang.String charset)Parse a JSON data structure from content at a given URL.java.lang.Objectparse(java.nio.file.Path path)Parse a JSON data structure from content within a given Path.java.lang.Objectparse(java.nio.file.Path path, java.lang.String charset)Parse a JSON data structure from content within a given Path.java.lang.Objectparse(java.util.Map params, java.net.URL url)Parse a JSON data structure from content at a given URL.java.lang.Objectparse(java.util.Map params, java.net.URL url, java.lang.String charset)Parse a JSON data structure from content at a given URL.java.lang.ObjectparseText(java.lang.String text)Parse a text representation of a JSON data structureJsonSlurpersetCheckDates(boolean checkDates)Determine if slurper will automatically parse strings it recognizes as dates.JsonSlurpersetChop(boolean chop)Turns on buffer chopping for index overlay.JsonSlurpersetLazyChop(boolean lazyChop)Turns on buffer lazy chopping for index overlay.JsonSlurpersetMaxSizeForInMemory(int maxSizeForInMemory)Max size before Slurper starts to use windowing buffer parser.JsonSlurpersetType(JsonParserType type)Parser type.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
- 
Constructor Details- 
JsonSlurperpublic JsonSlurper()
 
- 
- 
Method Details- 
getMaxSizeForInMemorypublic int getMaxSizeForInMemory()Max size before Slurper starts to use windowing buffer parser.- Returns:
- size of file/buffer
- Since:
- 2.3
 
- 
setMaxSizeForInMemoryMax size before Slurper starts to use windowing buffer parser.- Returns:
- JsonSlurper
- Since:
- 2.3
 
- 
getTypeParser type.- Returns:
- type
- Since:
- 2.3
- See Also:
- JsonParserType
 
- 
setTypeParser type.- Returns:
- JsonSlurper
- Since:
- 2.3
- See Also:
- JsonParserType
 
- 
isChoppublic boolean isChop()Turns on buffer chopping for index overlay.- Returns:
- chop on or off
- Since:
- 2.3
- See Also:
- JsonParserType
 
- 
setChopTurns on buffer chopping for index overlay.- Returns:
- JsonSlurper
- Since:
- 2.3
- See Also:
- JsonParserType
 
- 
isLazyChoppublic boolean isLazyChop()Turns on buffer lazy chopping for index overlay.- Returns:
- on or off
- Since:
- 2.3
- See Also:
- JsonParserType
 
- 
setLazyChopTurns on buffer lazy chopping for index overlay.- Returns:
- JsonSlurper
- Since:
- 2.3
- See Also:
- JsonParserType
 
- 
isCheckDatespublic boolean isCheckDates()Determine if slurper will automatically parse strings it recognizes as dates. Index overlay only.- Returns:
- on or off
- Since:
- 2.3
 
- 
setCheckDatesDetermine if slurper will automatically parse strings it recognizes as dates. Index overlay only.- Returns:
- on or off
- Since:
- 2.3
 
- 
parseTextpublic 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
 
- 
parsepublic 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
 
- 
parsepublic java.lang.Object parse(java.io.InputStream inputStream)Parse a JSON data structure from content from an inputStream- Parameters:
- inputStream- stream over a JSON content
- Returns:
- a data structure of lists and maps
- Since:
- 2.3
 
- 
parsepublic java.lang.Object parse(java.io.InputStream inputStream, java.lang.String charset)Parse a JSON data structure from content from an inputStream- Parameters:
- inputStream- stream over a JSON content
- charset- charset
- Returns:
- a data structure of lists and maps
- Since:
- 2.3
 
- 
parsepublic java.lang.Object parse(byte[] bytes, java.lang.String charset)Parse a JSON data structure from content from a byte array.- Parameters:
- bytes- buffer of JSON content
- charset- charset
- Returns:
- a data structure of lists and maps
- Since:
- 2.3
 
- 
parsepublic java.lang.Object parse(byte[] bytes)Parse a JSON data structure from content from a byte array.- Parameters:
- bytes- buffer of JSON content
- Returns:
- a data structure of lists and maps
- Since:
- 2.3
 
- 
parsepublic java.lang.Object parse(char[] chars)Parse a JSON data structure from content from a char array.- Parameters:
- chars- buffer of JSON content
- Returns:
- a data structure of lists and maps
- Since:
- 2.3
 
- 
parsepublic java.lang.Object parse(java.nio.file.Path path) throws java.io.IOExceptionParse a JSON data structure from content within a given Path.- Parameters:
- path-- Pathcontaining JSON content
- Returns:
- a data structure of lists and maps
- Throws:
- java.io.IOException
 
- 
parsepublic java.lang.Object parse(java.nio.file.Path path, java.lang.String charset) throws java.io.IOExceptionParse a JSON data structure from content within a given Path.- Parameters:
- path-- Pathcontaining JSON content
- charset- the charset for this File
- Returns:
- a data structure of lists and maps
- Throws:
- java.io.IOException
 
- 
parsepublic java.lang.Object parse(java.io.File file)Parse a JSON data structure from content within a given File.- Parameters:
- file- File containing JSON content
- Returns:
- a data structure of lists and maps
- Since:
- 2.2.0
 
- 
parsepublic java.lang.Object parse(java.io.File file, java.lang.String charset)Parse a JSON data structure from content within a given File.- Parameters:
- file- File containing JSON content
- charset- the charset for this File
- Returns:
- a data structure of lists and maps
- Since:
- 2.2.0
 
- 
parsepublic java.lang.Object parse(java.net.URL url)Parse a JSON data structure from content at a given URL.- Parameters:
- url- URL containing JSON content
- Returns:
- a data structure of lists and maps
- Since:
- 2.2.0
 
- 
parsepublic java.lang.Object parse(java.net.URL url, java.util.Map params)Parse a JSON data structure from content at a given URL.- Parameters:
- url- URL containing JSON content
- params- connection parameters
- Returns:
- a data structure of lists and maps
- Since:
- 2.2.0
 
- 
parsepublic java.lang.Object parse(java.util.Map params, java.net.URL url)Parse a JSON data structure from content at a given URL. Convenience variant when using Groovy named parameters for the connection params.- Parameters:
- params- connection parameters
- url- URL containing JSON content
- Returns:
- a data structure of lists and maps
- Since:
- 2.2.0
 
- 
parsepublic java.lang.Object parse(java.net.URL url, java.lang.String charset)Parse a JSON data structure from content at a given URL.- Parameters:
- url- URL containing JSON content
- charset- the charset for this File
- Returns:
- a data structure of lists and maps
- Since:
- 2.2.0
 
- 
parsepublic java.lang.Object parse(java.net.URL url, java.util.Map params, java.lang.String charset)Parse a JSON data structure from content at a given URL.- Parameters:
- url- URL containing JSON content
- params- connection parameters
- charset- the charset for this File
- Returns:
- a data structure of lists and maps
- Since:
- 2.2.0
 
- 
parsepublic java.lang.Object parse(java.util.Map params, java.net.URL url, java.lang.String charset)Parse a JSON data structure from content at a given URL. Convenience variant when using Groovy named parameters for the connection params.- Parameters:
- params- connection parameters
- url- URL containing JSON content
- charset- the charset for this File
- Returns:
- a data structure of lists and maps
- Since:
- 2.2.0
 
 
-