Skip to main content

JSON Formatter

Formats a writer's output as JSON.

JSON Formatter properties

property

type

default value

notes

Charset

String

Events as Array of JSON Objects

Boolean

True

With the default value True, output is an array:

[
  {field1:value1,field2:value2,.....} ,
  {field1:value1,field2:value2,.....} ,
  {field1:value1,field2:value2,.....} ]

Set to False to output a collection:

{field1:value1,field2:value2,.....} 
{field1:value1,field2:value2,.....} 
{field1:value1,field2:value2,.....}

JSON Member Delimiter

String

\n

JSON Object Delimiter

String

\n

Members

String

comma-separated list of fields to be selected from the writer's input stream; if left  blank, selects all fields

One use for this property is to remove fields used only to name the output directory in the target (see Setting output names and rollover / upload policies).

If source column names contain any of the special characters listed in Using non-default case and special characters in table identifiers, they will be used in the corresponding field names in the JSON output.Using non-default case and special characters in table identifiers

JSON Formatter sample application

For example, this variation on the PosApp sample application writes to a file using JSONFormatter:

CREATE SOURCE CsvDataSource USING FileReader (
  directory:'Samples/PosApp/appData',
  wildcard:'PosDataPreview.csv',
  positionByEOF:false
)
PARSE USING DSVParser (
  header:Yes,
  trimquote:false
) OUTPUT TO CsvStream;
  
CREATE CQ CsvToPosData
INSERT INTO PosDataStream
SELECT TO_STRING(data[1]) as merchantId,
  TO_DOUBLE(data[7]) as amount,
  TO_STRING(data[9]) as zip
FROM CsvStream;

CREATE TARGET JFFileOut USING FileWriter(
  filename:'JFTestOutput.json'
)
FORMAT USING JSONFormatter()
INPUT FROM PosDataStream;

The first lines of JSONFormatterOutput are:

[
 {
  "merchantId":"D6RJPwyuLXoLqQRQcOcouJ26KGxJSf6hgbu",
  "dateTime":"2013-03-12T17:32:10.000-07:00",
  "amount":2.2
 },
 {
  "merchantId":"OFp6pKTMg26n1iiFY00M9uSqh9ZfMxMBRf1",
  "dateTime":"2013-03-12T17:32:10.000-07:00",
  "amount":22.78
 },