com.orsoncharts.data

## Class JSONUtils

- java.lang.Object
- - com.orsoncharts.data.JSONUtils

-     public class JSONUtils
      extends java.lang.Object

  Utility methods for interchange between datasets (`KeyedValues`, `KeyedValues3D` and `XYZDataset`) and JSON format strings.
  Since:
    1.3

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `JSONUtils()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static KeyedValues<? extends java.lang.Number>` | `readKeyedValues(java.io.Reader reader)` Parses characters from the supplied reader and returns the corresponding `KeyedValues` instance.
    `static KeyedValues<? extends java.lang.Number>` | `readKeyedValues(java.lang.String json)` Parses the supplied JSON string into a `KeyedValues` instance.
    `static KeyedValues2D<? extends java.lang.Number>` | `readKeyedValues2D(java.io.Reader reader)` Reads a data table from a JSON format string coming from the specified reader.
    `static KeyedValues2D<? extends java.lang.Number>` | `readKeyedValues2D(java.lang.String json)` Reads a data table from a JSON format string.
    `static KeyedValues3D<? extends java.lang.Number>` | `readKeyedValues3D(java.io.Reader reader)` Parses character data from the reader and (if possible) creates a `KeyedValues3D` instance.
    `static KeyedValues3D<? extends java.lang.Number>` | `readKeyedValues3D(java.lang.String json)` Parses the supplied string and (if possible) creates a `KeyedValues3D` instance.
    `static XYZDataset` | `readXYZDataset(java.io.Reader reader)` Parses character data from the reader and (if possible) creates an {XYZDataset} instance that represents the data.
    `static XYZDataset` | `readXYZDataset(java.lang.String json)` Parses the string and (if possible) creates an {XYZDataset} instance that represents the data.
    `static java.lang.String` | `writeKeyedValues(KeyedValues<? extends java.lang.Number> data)` Returns a string containing the data in JSON format.
    `static void` | `writeKeyedValues(KeyedValues<? extends java.lang.Number> data, java.io.Writer writer)` Writes the data in JSON format to the supplied writer.
    `static java.lang.String` | `writeKeyedValues2D(KeyedValues2D<? extends java.lang.Number> data)` Writes a data table to a string in JSON format.
    `static void` | `writeKeyedValues2D(KeyedValues2D<? extends java.lang.Number> data, java.io.Writer writer)` Writes the data in JSON format to the supplied writer.
    `static java.lang.String` | `writeKeyedValues3D(KeyedValues3D<? extends java.lang.Number> dataset)` Returns a string containing the data in JSON format.
    `static void` | `writeKeyedValues3D(KeyedValues3D<? extends java.lang.Number> dataset, java.io.Writer writer)` Writes the dataset in JSON format to the supplied writer.
    `static java.lang.String` | `writeXYZDataset(XYZDataset dataset)` Returns a string containing the dataset in JSON format.
    `static void` | `writeXYZDataset(XYZDataset dataset, java.io.Writer writer)` Writes the dataset in JSON format to the supplied writer.

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

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

- - ### Constructor Detail

    - #### JSONUtils

          public JSONUtils()

  - ### Method Detail

    - #### readKeyedValues

          public static KeyedValues<? extends java.lang.Number> readKeyedValues(java.lang.String json)

      Parses the supplied JSON string into a `KeyedValues` instance.
      Implementation note: this method returns an instance of `StandardPieDataset3D`).
      Parameters:
        `json` - the JSON string (`null` not permitted).
      Returns:
        A `KeyedValues` instance.

    - #### readKeyedValues

          public static KeyedValues<? extends java.lang.Number> readKeyedValues(java.io.Reader reader)
                                                                         throws java.io.IOException

      Parses characters from the supplied reader and returns the corresponding `KeyedValues` instance.
      Implementation note: this method returns an instance of `StandardPieDataset3D`).
      Parameters:
        `reader` - the reader (`null` not permitted).
      Returns:
        A `KeyedValues` instance.
      Throws:
        `java.io.IOException` - if there is an I/O problem.

    - #### writeKeyedValues

          public static java.lang.String writeKeyedValues(KeyedValues<? extends java.lang.Number> data)

      Returns a string containing the data in JSON format. The format is an array of arrays, where each sub-array represents one data value. The sub-array should contain two items, first the item key as a string and second the item value as a number. For example: `[["Key A", 1.0], ["Key B", 2.0]]`
      Note that this method can be used with instances of `PieDataset3D`.
      Parameters:
        `data` - the data (`null` not permitted).
      Returns:
        A string in JSON format.

    - #### writeKeyedValues

          public static void writeKeyedValues(KeyedValues<? extends java.lang.Number> data,
                                              java.io.Writer writer)
                                       throws java.io.IOException

      Writes the data in JSON format to the supplied writer.
      Note that this method can be used with instances of `PieDataset3D`.
      Parameters:
        `data` - the data (`null` not permitted).
        `writer` - the writer (`null` not permitted).
      Throws:
        `java.io.IOException` - if there is an I/O problem.

    - #### readKeyedValues2D

          public static KeyedValues2D<? extends java.lang.Number> readKeyedValues2D(java.lang.String json)

      Reads a data table from a JSON format string.
      Parameters:
        `json` - the string (`null` not permitted).
      Returns:
        A data table.

    - #### readKeyedValues2D

          public static KeyedValues2D<? extends java.lang.Number> readKeyedValues2D(java.io.Reader reader)
                                                                             throws java.io.IOException

      Reads a data table from a JSON format string coming from the specified reader.
      Parameters:
        `reader` - the reader (`null` not permitted).
      Returns:
        A data table.
      Throws:
        `java.io.IOException` - if there is an I/O problem.

    - #### writeKeyedValues2D

          public static java.lang.String writeKeyedValues2D(KeyedValues2D<? extends java.lang.Number> data)

      Writes a data table to a string in JSON format.
      Parameters:
        `data` - the data (`null` not permitted).
      Returns:
        The string.

    - #### writeKeyedValues2D

          public static void writeKeyedValues2D(KeyedValues2D<? extends java.lang.Number> data,
                                                java.io.Writer writer)
                                         throws java.io.IOException

      Writes the data in JSON format to the supplied writer.
      Parameters:
        `data` - the data (`null` not permitted).
        `writer` - the writer (`null` not permitted).
      Throws:
        `java.io.IOException` - if there is an I/O problem.

    - #### readKeyedValues3D

          public static KeyedValues3D<? extends java.lang.Number> readKeyedValues3D(java.lang.String json)

      Parses the supplied string and (if possible) creates a `KeyedValues3D` instance.
      Parameters:
        `json` - the JSON string (`null` not permitted).
      Returns:
        A `KeyedValues3D` instance.

    - #### readKeyedValues3D

          public static KeyedValues3D<? extends java.lang.Number> readKeyedValues3D(java.io.Reader reader)
                                                                             throws java.io.IOException

      Parses character data from the reader and (if possible) creates a `KeyedValues3D` instance. This method will read back the data written by `writeKeyedValues3D( com.orsoncharts.data.KeyedValues3D, java.io.Writer)`.
      Parameters:
        `reader` - the reader (`null` not permitted).
      Returns:
        A `KeyedValues3D` instance.
      Throws:
        `java.io.IOException` - if there is an I/O problem.

    - #### writeKeyedValues3D

          public static java.lang.String writeKeyedValues3D(KeyedValues3D<? extends java.lang.Number> dataset)

      Returns a string containing the data in JSON format.
      Parameters:
        `dataset` - the data (`null` not permitted).
      Returns:
        A string in JSON format.

    - #### writeKeyedValues3D

          public static void writeKeyedValues3D(KeyedValues3D<? extends java.lang.Number> dataset,
                                                java.io.Writer writer)
                                         throws java.io.IOException

      Writes the dataset in JSON format to the supplied writer.
      Parameters:
        `dataset` - the dataset (`null` not permitted).
        `writer` - the writer (`null` not permitted).
      Throws:
        `java.io.IOException` - if there is an I/O problem.

    - #### readXYZDataset

          public static XYZDataset readXYZDataset(java.lang.String json)

      Parses the string and (if possible) creates an {XYZDataset} instance that represents the data. This method will read back the data that is written by `writeXYZDataset(com.orsoncharts.data.xyz.XYZDataset)`.
      Parameters:
        `json` - a JSON formatted string (`null` not permitted).
      Returns:
        A dataset.
      See Also:
        `writeXYZDataset(com.orsoncharts.data.xyz.XYZDataset)`

    - #### readXYZDataset

          public static XYZDataset readXYZDataset(java.io.Reader reader)
                                           throws java.io.IOException

      Parses character data from the reader and (if possible) creates an {XYZDataset} instance that represents the data.
      Parameters:
        `reader` - a reader (`null` not permitted).
      Returns:
        A dataset.
      Throws:
        `java.io.IOException` - if there is an I/O problem.

    - #### writeXYZDataset

          public static java.lang.String writeXYZDataset(XYZDataset dataset)

      Returns a string containing the dataset in JSON format.
      Parameters:
        `dataset` - the dataset (`null` not permitted).
      Returns:
        A string in JSON format.

    - #### writeXYZDataset

          public static void writeXYZDataset(XYZDataset dataset,
                                             java.io.Writer writer)
                                      throws java.io.IOException

      Writes the dataset in JSON format to the supplied writer.
      Parameters:
        `dataset` - the data (`null` not permitted).
        `writer` - the writer (`null` not permitted).
      Throws:
        `java.io.IOException` - if there is an I/O problem.