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.String compactPrint(java.lang.Object value)

Represents the value in JSON, compact form (keys are not sorted)

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

Given a json string, convert it to a value (map / list) depending on if the json starts with [ or { (with proper null handling).

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

static ObjectMapper newJacksonMapper(java.lang.Object sorting)

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

Represents the value in JSON, nicely indented and human readable

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

Represents the value in JSON, nicely indented and human readable depending on 'indent'

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)


compactPrint

static java.lang.String compactPrint(java.lang.Object value)
Represents the value in JSON, compact form (keys are not sorted)


fromJSON

static java.lang.Object fromJSON(java.lang.String json)
Given a json string, convert it to a value (map / list) depending on if the json starts with [ or { (with proper null handling).


mapToJSON

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


newJacksonMapper

static ObjectMapper newJacksonMapper(java.lang.Object sorting)


prettyPrint

static java.lang.String prettyPrint(java.lang.Object value)
Represents the value in JSON, nicely indented and human readable


prettyPrint

static java.lang.String prettyPrint(java.lang.Object value, int indent)
Represents the value in JSON, nicely indented and human readable depending on 'indent'


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