Description

The JSONFileReceiver receives data from a given GenRocket Domain and writes the data out to a file in JSON format.

Note: This particular JSON Receiver does not allow for nested elements. To generate nested JSON, assign the SegmentDataCreatorReceiver to each Domain and then assign the JSONSegmentMergeReceiver to a Merge Domain. 


In This Article


Receiver Parameters

The JSONFileReceiver requires that the following parameters are defined. Items with an asterisk * are required.

  • path* - Defines the location to store the newly generated JSON output file.
  • subDir - Defines the subdirectory path under the output directory path to store the output file. 
  • fileName* - Defines the name of the output file.
  • rootElementName - Defines the root element of the JSON structure.
  • alwaysArray - If "true", then it will create a JSON array irrespective of the number of records in a file is one or more. If "false:, it will create a JSON array only if the number of records is more than one. Otherwise, it will create a JSON object. The default value is false. 


Receiver Attribute Property Keys

The Receiver defines three property keys that can be modified on any of its associated Domain Attributes:

  • columnName - Defines the column name as it will be output in the delimited file header.
  • include - Determines if the Attribute will be included as a column in the output.
  • useQuotes - Determines if a value should be quoted. Sometimes a numeric value should be quoted (e.g., SSN).


File and Directory Config Tabs

The File and Directory Config Tabs are used to configure what event will trigger file/directory creation and the naming configuration for generated files/directories. Please click here for more information on how to use the File and Directory Config Tabs. 



Use Case 1 - Generating a JSON Output File

This story demonstrates how to output data to a JSON file for a User Domain with the following Attributes:
 


Parameter Configuration

Only the required parameters (resourcePath and fileName) will be configured for this example. The parameter configuration will appear as shown below: 



Sample Output

The following is an example JSON output file for the User Domain in this use case.

Tex
{
  "users" : [
    {
      "id" : "1",
      "firstName" : "Alexa",
      "lastName" : "Topete",
      "middleInitial" : "G",
      "username" : "user1",
      "password" : "C4CA4238A0B923820DCC509A6F75849B",
      "phoneNumber" : "(308) 575-6657"
    },
    {
      "id" : "2",
      "firstName" : "Sibyl",
      "lastName" : "Epstein",
      "middleInitial" : "T",
      "username" : "user2",
      "password" : "C81E728D9D4C2F636F067F89CC14862C",
      "phoneNumber" : "(739) 798-3806"
    },
    {
      "id" : "3",
      "firstName" : "Norman",
      "lastName" : "Marini",
      "middleInitial" : "P",
      "username" : "user3",
      "password" : "ECCBC87E4B5CE2FE28308FD9F2A7BAF3",
      "phoneNumber" : "(616) 545-8376"
    }
  ]
}