Class JsonDataSet

All Implemented Interfaces:
IDataSet, IDataSetConsumer

public class JsonDataSet extends CachedDataSet
Reads and writes flat JSON-based dataset documents.

Contrary to the flat XML layout, columns are calculated by parsing the entire dataset, not just the first row. Each table is a top-level key in the JSON object, and its value is an array of row objects. Columns with null values are omitted from the JSON representation.

Example:

 {
   "TEST_TABLE": [
     {"COL0": "row 0 col 0", "COL1": "row 0 col 1"},
     {"COL0": "row 1 col 0"}
   ],
   "EMPTY_TABLE": []
 }
 
Author:
Jeff Jensen
  • Constructor Details

    • JsonDataSet

      public JsonDataSet(File file) throws IOException, DataSetException
      Creates a JSON dataset from the given file.
      Parameters:
      file - The JSON file to read.
      Throws:
      IOException - If the file cannot be opened.
      DataSetException - If the JSON content cannot be parsed as a dataset.
    • JsonDataSet

      public JsonDataSet(InputStream inputStream) throws DataSetException
      Creates a JSON dataset from the given input stream. The stream is left open once reading completes; the caller remains responsible for closing it.
      Parameters:
      inputStream - The stream containing JSON dataset data.
      Throws:
      DataSetException - If the JSON content cannot be parsed as a dataset.
  • Method Details

    • write

      public static void write(IDataSet dataSet, OutputStream out) throws DataSetException
      Writes the specified dataset to the given output stream as JSON, encoded in UTF-8, matching what JsonProducer decodes.
      Parameters:
      dataSet - The dataset to write.
      out - The stream to write to.
      Throws:
      DataSetException - If the dataset cannot be serialized.
    • write

      public static void write(IDataSet dataSet, Writer out) throws DataSetException
      Writes the specified dataset to the given writer as JSON.
      Parameters:
      dataSet - The dataset to write.
      out - The writer to write to.
      Throws:
      DataSetException - If the dataset cannot be serialized.