Groovy Documentation

org.linkedin.groovy.util.json
[Groovy] Class JsonUtils

java.lang.Object
  org.linkedin.groovy.util.json.JsonUtils

class JsonUtils

Contains utilities for json.

Authors:
ypujante@linkedin.com


Method Summary
static java.lang.Object collectionToJSON(java.util.Collection list)

static java.lang.Object fromJSON(java.lang.String json)

Given a json string, convert it to a value (maps / lists): equivalent to toValue(new JSONObject(json)) or toValue(new JSONArray(json) depending on if the json starts with [ or { (with proper null handling).

static java.lang.Object mapToJSON(java.util.Map map)

static java.lang.String prettyPrint(java.lang.Object value)

Converts the value to a json object and displays it nicely indented

static java.lang.String prettyPrint(java.lang.Object value, int indent)

Converts the value to a json object and displays it nicely indented

static java.lang.Object toJSON(java.lang.Object value)

Reverse method which converts a value into a json value

static java.lang.Object toList(JSONArray array)

Converts the json array into a list (recursive call).

static java.lang.Object toMap(JSONObject json)

Converts a json object into a map (recursive call).

static java.lang.Object toValue(java.lang.Object value)

Converts the value into its non JSON counter part: if the value is a org.json.JSONObject or a org.json.JSONArray then it will call the appropriate method, otherwise simply return the value.

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Method Detail

collectionToJSON

static java.lang.Object collectionToJSON(java.util.Collection list)


fromJSON

static java.lang.Object fromJSON(java.lang.String json)
Given a json string, convert it to a value (maps / lists): equivalent to toValue(new JSONObject(json)) or toValue(new JSONArray(json) depending on if the json starts with [ or { (with proper null handling).


mapToJSON

static java.lang.Object mapToJSON(java.util.Map map)


prettyPrint

static java.lang.String prettyPrint(java.lang.Object value)
Converts the value to a json object and displays it nicely indented


prettyPrint

static java.lang.String prettyPrint(java.lang.Object value, int indent)
Converts the value to a json object and displays it nicely indented


toJSON

static java.lang.Object toJSON(java.lang.Object value)
Reverse method which converts a value into a json value


toList

static java.lang.Object toList(JSONArray array)
Converts the json array into a list (recursive call).


toMap

static java.lang.Object toMap(JSONObject json)
Converts a json object into a map (recursive call).


toValue

static java.lang.Object toValue(java.lang.Object value)
Converts the value into its non JSON counter part: if the value is a org.json.JSONObject or a org.json.JSONArray then it will call the appropriate method, otherwise simply return the value.


 

Groovy Documentation