Created
February 26, 2011 13:45
-
-
Save fumokmm/845209 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
["aaa", "bbb", "ccc"], | |
{ | |
"key1" : "value1", | |
"key2" : "value2", | |
"key3" : "value3", | |
"key4" : "" | |
}, | |
["ddd", "eee", "fff"] | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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