JSON Slurper in Groovy
What is JSON slurper?
JSON slurper is a class in groovy that can be used to parse text or read content into a data structure of lists and maps.
In other words we can say that it converts the json string into list and maps, which can be used effectivly in the code.
Example :
import groovy.json.JsonSlurper; def jsonSlurper = new JsonSlurper() def output = jsonSlurper.parseText('{"employee":{"id":"hdev021","dob":23/1/1987,"skillset":["c","java","oracle","design patterns"]}}')
Here we can see that the String is being parsed by jsonSlurper object and the output is now a json object.
The fields can be accessed by dot (.) notation directly in the code
print output.employee.id // Prints the following hdev021
JsonSlurper can use several types of JSON parsers.
1. INDEX_OVERLAY (Used in REST calls) 2. CHAR_BUFFER (parses the datatypes like integer, date time, long etc) 3. CHARACTER_SOURCE (This is used when json string is large). 4. LAX (Relax json parsing comments, no quote strings, etc are allowed) 5. CHAR_BUFFER (is a super fast parser)
The following types can be set by using the method setType of JsonSlurper
Best Open Source Business Intelligence Software Helical Insight is Here
A Business Intelligence Framework
Source: internet.
database ETL JavaScript JSON
Subscribe
Login
0 Comments