Skip to content

Instantly share code, notes, and snippets.

@fumokmm
Created February 26, 2011 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fumokmm/845209 to your computer and use it in GitHub Desktop.
Save fumokmm/845209 to your computer and use it in GitHub Desktop.
[
["aaa", "bbb", "ccc"],
{
"key1" : "value1",
"key2" : "value2",
"key3" : "value3",
"key4" : ""
},
["ddd", "eee", "fff"]
]
import groovy.json.*
def slurper = new JsonSlurper()
def text = new File('json.txt').text
def root = slurper.parseText(text)
assert root == [
['aaa', 'bbb', 'ccc'],
[key1: 'value1', key2: 'value2', key3: 'value3', key4: ''],
['ddd', 'eee', 'fff']
]
assert root instanceof ArrayList
assert root[0] instanceof ArrayList
assert root[1] instanceof HashMap
assert root[2] instanceof ArrayList
assert root[1].key3 == 'value3'
assert root.last().last() == 'fff'
import groovy.json.*
def json = new JsonBuilder()
json (
['aaa', 'bbb', 'ccc'],
[
key1: 'value1',
key2: 'value2',
key3: 'value3',
key4: ''
],
['ddd', 'eee', 'fff']
)
new File('json2.txt').text = json.toString()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment