Package groovy.json
Class JsonOutput
- java.lang.Object
- 
- groovy.json.JsonOutput
 
- 
 public class JsonOutput extends Object Class responsible for the actual String serialization of the possible values of a JSON structure. This class can also be used as a category, so as to addtoJson()methods to various types.This class does not provide the ability to customize the resulting output. A JsonGeneratorcan be used if the ability to alter the resulting output is required.- Since:
- 1.8.0
- See Also:
- JsonGenerator
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classJsonOutput.JsonUnescapedRepresents unescaped JSON
 - 
Constructor SummaryConstructors Constructor Description JsonOutput()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static StringprettyPrint(String jsonPayload)Pretty print a JSON payload.static StringtoJson(Closure closure)static StringtoJson(Expando expando)static StringtoJson(Boolean bool)static StringtoJson(Character c)static StringtoJson(Number n)static StringtoJson(Object object)static StringtoJson(String s)static StringtoJson(URL url)static StringtoJson(Calendar cal)Format a calendar instance that is parseable from JavaScript, according to ISO-8601.static StringtoJson(Date date)Format a date that is parseable from JavaScript, according to ISO-8601.static StringtoJson(Map m)static StringtoJson(UUID uuid)static JsonOutput.JsonUnescapedunescaped(CharSequence text)Obtains JSON unescaped text for the given text
 
- 
- 
- 
Method Detail- 
toJsonpublic static String toJson(Number n) - Returns:
- a string representation for a number
- Throws:
- JsonException- if the number is infinite or not a number.
 
 - 
toJsonpublic static String toJson(Character c) - Returns:
- a JSON string representation of the character
 
 - 
toJsonpublic static String toJson(String s) - Returns:
- a properly encoded string with escape sequences
 
 - 
toJsonpublic static String toJson(Date date) Format a date that is parseable from JavaScript, according to ISO-8601.- Parameters:
- date- the date to format to a JSON string
- Returns:
- a formatted date in the form of a string
 
 - 
toJsonpublic static String toJson(Calendar cal) Format a calendar instance that is parseable from JavaScript, according to ISO-8601.- Parameters:
- cal- the calendar to format to a JSON string
- Returns:
- a formatted date in the form of a string
 
 - 
toJsonpublic static String toJson(Expando expando) - Returns:
- an object representation of an Expando
 
 - 
toJsonpublic static String toJson(Object object) - Returns:
- "null" for a null value, or a JSON array representation for a collection, array, iterator or enumeration, or representation for other object.
 
 - 
prettyPrintpublic static String prettyPrint(String jsonPayload) Pretty print a JSON payload.- Parameters:
- jsonPayload-
- Returns:
- a pretty representation of JSON payload.
 
 - 
unescapedpublic static JsonOutput.JsonUnescaped unescaped(CharSequence text) Obtains JSON unescaped text for the given text- Parameters:
- text- The text
- Returns:
- The unescaped text
 
 
- 
 
-