Package groovy.json
Class JsonOutput
java.lang.Object
groovy.json.JsonOutput
public class JsonOutput
extends java.lang.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 add 
toJson() methods to various types.
 
 This class does not provide the ability to customize the resulting output.  A JsonGenerator
 can 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 SummaryModifier and Type Method Description static java.lang.StringprettyPrint(java.lang.String jsonPayload)Pretty print a JSON payload.static java.lang.StringtoJson(Closure closure)static java.lang.StringtoJson(Expando expando)static java.lang.StringtoJson(java.lang.Boolean bool)static java.lang.StringtoJson(java.lang.Character c)static java.lang.StringtoJson(java.lang.Number n)static java.lang.StringtoJson(java.lang.Object object)static java.lang.StringtoJson(java.lang.String s)static java.lang.StringtoJson(java.net.URL url)static java.lang.StringtoJson(java.util.Calendar cal)Format a calendar instance that is parseable from JavaScript, according to ISO-8601.static java.lang.StringtoJson(java.util.Date date)Format a date that is parseable from JavaScript, according to ISO-8601.static java.lang.StringtoJson(java.util.Map m)static java.lang.StringtoJson(java.util.UUID uuid)static JsonOutput.JsonUnescapedunescaped(java.lang.CharSequence text)Obtains JSON unescaped text for the given textMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
- 
Constructor Details- 
JsonOutputpublic JsonOutput()
 
- 
- 
Method Details- 
toJsonpublic static java.lang.String toJson(java.lang.Boolean bool)- Returns:
- "true" or "false" for a boolean value
 
- 
toJsonpublic static java.lang.String toJson(java.lang.Number n)- Returns:
- a string representation for a number
- Throws:
- JsonException- if the number is infinite or not a number.
 
- 
toJsonpublic static java.lang.String toJson(java.lang.Character c)- Returns:
- a JSON string representation of the character
 
- 
toJsonpublic static java.lang.String toJson(java.lang.String s)- Returns:
- a properly encoded string with escape sequences
 
- 
toJsonpublic static java.lang.String toJson(java.util.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 java.lang.String toJson(java.util.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 java.lang.String toJson(java.util.UUID uuid)- Returns:
- the string representation of an uuid
 
- 
toJsonpublic static java.lang.String toJson(java.net.URL url)- Returns:
- the string representation of the URL
 
- 
toJson- Returns:
- an object representation of a closure
 
- 
toJson- Returns:
- an object representation of an Expando
 
- 
toJsonpublic static java.lang.String toJson(java.lang.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.
 
- 
toJsonpublic static java.lang.String toJson(java.util.Map m)- Returns:
- a JSON object representation for a map
 
- 
prettyPrintpublic static java.lang.String prettyPrint(java.lang.String jsonPayload)Pretty print a JSON payload.- Parameters:
- jsonPayload-
- Returns:
- a pretty representation of JSON payload.
 
- 
unescapedObtains JSON unescaped text for the given text- Parameters:
- text- The text
- Returns:
- The unescaped text
 
 
-