Groovy Documentation

## groovy.json
[Groovy] Class JsonOutput

    java.lang.Object
      groovy.json.JsonOutput

    class JsonOutput

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.

Authors:
  Guillaume Laforge
  Roshan Dawrani

Since:
  1.8.0

Method Summary
`static java.lang.String` | `prettyPrint(java.lang.String jsonPayload)` Pretty print a JSON payload
`static java.lang.String` | `toJson(java.lang.Boolean bool)` @return "true" or "false" for a boolean value
`static java.lang.String` | `toJson(java.lang.Number n)` @return a string representation for a number
`static java.lang.String` | `toJson(java.lang.Character c)` @return a JSON string representation of the character
`static java.lang.String` | `toJson(java.lang.String s)` @return a properly encoded string with escape sequences
`static java.lang.String` | `toJson(java.util.Date date)` Format a date that is parseable from JavaScript, according to ISO-8601.
`static java.lang.String` | `toJson(java.util.Calendar cal)` Format a calendar instance that is parseable from JavaScript, according to ISO-8601.
`static java.lang.String` | `toJson(java.util.UUID uuid)` @return the string representation of an uuid
`static java.lang.String` | `toJson(java.net.URL url)` @return the string representation of the URL
`static java.lang.String` | `toJson(Closure closure)` @return an object representation of a closure
`static java.lang.String` | `toJson(java.lang.Object object)` @return "null" for a null value, or a JSON array representation for a collection, array, iterator or enumeration.
`static java.lang.String` | `toJson(java.util.Map m)` @return a JSON object representation for a map

Methods inherited from class java.lang.Object
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), 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

### prettyPrint

    static java.lang.String prettyPrint(java.lang.String jsonPayload)

  Pretty print a JSON payload
  Parameters:
    jsonPayload
  Returns:

### toJson

    static java.lang.String toJson(java.lang.Boolean bool)

  Returns:
    "true" or "false" for a boolean value

### toJson

    static java.lang.String toJson(java.lang.Number n)

  throws:
    JsonException if the number is infinite or not a number.
  Returns:
    a string representation for a number

### toJson

    static java.lang.String toJson(java.lang.Character c)

  Returns:
    a JSON string representation of the character

### toJson

    static java.lang.String toJson(java.lang.String s)

  Returns:
    a properly encoded string with escape sequences

### toJson

    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

### toJson

    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

### toJson

    static java.lang.String toJson(java.util.UUID uuid)

  Returns:
    the string representation of an uuid

### toJson

    static java.lang.String toJson(java.net.URL url)

  Returns:
    the string representation of the URL

### toJson

    static java.lang.String toJson(Closure closure)

  Returns:
    an object representation of a closure

### toJson

    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.

### toJson

    static java.lang.String toJson(java.util.Map m)

  Returns:
    a JSON object representation for a map

Groovy Documentation