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 add `toJson()` methods to various types.
  Since:
    1.8.0
  Author:
    Guillaume Laforge, Roshan Dawrani, Andrey Bloschetsov, Rick Hightower

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `JsonOutput()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `prettyPrint(String jsonPayload)` Pretty print a JSON payload.
    `static String` | `toJson(Boolean bool)`
    `static String` | `toJson(Calendar cal)` Format a calendar instance that is parseable from JavaScript, according to ISO-8601.
    `static String` | `toJson(Character c)`
    `static String` | `toJson(Closure closure)`
    `static String` | `toJson(Date date)` Format a date that is parseable from JavaScript, according to ISO-8601.
    `static String` | `toJson(Expando expando)`
    `static String` | `toJson(Map m)`
    `static String` | `toJson(Number n)`
    `static String` | `toJson(Object object)`
    `static String` | `toJson(String s)`
    `static String` | `toJson(URL url)`
    `static String` | `toJson(UUID uuid)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### JsonOutput

          public JsonOutput()

  - ### Method Detail

    - #### toJson

          public static String toJson(Boolean bool)

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

    - #### toJson

          public static String toJson(Number n)

      Returns:
        a string representation for a number
      Throws:
        `JsonException` - if the number is infinite or not a number.

    - #### toJson

          public static String toJson(Character c)

      Returns:
        a JSON string representation of the character

    - #### toJson

          public static String toJson(String s)

      Returns:
        a properly encoded string with escape sequences

    - #### toJson

          public 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

    - #### toJson

          public 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

    - #### toJson

          public static String toJson(UUID uuid)

      Returns:
        the string representation of an uuid

    - #### toJson

          public static String toJson(URL url)

      Returns:
        the string representation of the URL

    - #### toJson

          public static String toJson(Closure closure)

      Returns:
        an object representation of a closure

    - #### toJson

          public static String toJson(Expando expando)

      Returns:
        an object representation of an Expando

    - #### toJson

          public 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.

    - #### toJson

          public static String toJson(Map m)

      Returns:
        a JSON object representation for a map

    - #### prettyPrint

          public static String prettyPrint(String jsonPayload)

      Pretty print a JSON payload.
      Parameters:
        `jsonPayload` -
      Returns:
        a pretty representation of JSON payload.