Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

On this Page

Table of Contents
maxLevel2
excludeOlder Versions|Additional Resources|Related Links|Related Information

Snap Type:

Transform

Description:

This Snap reads JSON document data from its input view, and formats and writes it as JSON binary data to its output view.  A schema file can also be attached to the Snap that allows it to share the schema with upstream Snaps like the Mapper Snap.  

Prerequisites:

None

Support and limitations:

Works in Ultra Pipelines if Format each document is selected. 

Account: 

Accounts are not used with this Snap.

Views:
InputThis Snap has exactly one document input view, where it gets the JSON document data to be formatted.
OutputThis Snap has exactly one binary output view, where it provides the JSON binary data stream.
ErrorThis Snap has at most one document error view and produces zero or more documents in the view.

 

Settings

Label 

Required. The name for the Snap. You can modify this to be more specific, especially if you have more than one of the same Snap in your Pipeline.Schema

For uploading JSON schema files, this is helpful when the formatted JSON has to follow a certain schema. This is particularly useful when used with Mapper Snap, the schema from the JSON Formatter Snap will be back-propagated to the Mapper Snap. This is a suggestible property, click on the browse button to select file from your project folder.

Example: contact.schema

Default value: [None]

Note

The Pipeline should be validated once when the schema file has been uploaded in order for the schema to be visible in the upstream Snap.

Binary Header Properties

The properties to add to the binary document's header.  The properties in the header of a binary document can be accessed in expression properties of downstream Snaps.  For example, a 'content-location' property added to the header in this Snap can be referenced in the file name property of a File Writer snap with the expression: $['content-location'].  When this Snap is configured to output a single binary document, the headers are computed from the first input document.  When the "Format each document" option is enabled, the headers are computed separately for each binary output.

Expression

Enter the function to be used to transform the data such as combine, concat or flatten.

Default value: None

Target Path

Enter in the target JSON path where the value from the expression will be written.

Example: $person.firstname to write the field 'firstname' of the 'person' object.

Default value:  None

Content

The input object or field whose data must be written to the output stream. For example, $payload or $emp_salary. Use $ to write the entire data.

See Filtering Output Data Using the JSON Formatter Snap's Content Setting further in this page for filtering the input data based on the Content field.

Default value: $

Ignore empty stream

Required in Standard mode. The Ignore empty stream property specifies that an empty array will be written to the output view in case no documents were received on the input view (disabled).
Will write nothing to the output view in case no documents were received on the input view if the property is enabled 

Default value: Not Selected

Format each document

If enabled, the property defines that one binary output stream is created for every document on its input view. If disabled, will write one binary output stream for all documents on its input view which are enclosed by a JSON array element [ .. ]. 

Default value: Not Selected  

JSON lines

If selected, writes all documents to a single output file, with each document appearing as a single line followed by a new line. This field cannot be used with Format each document or Pretty-print properties. 

Default value: Not selected  

Pretty-print

If enabled, formats the output to make it more readable/printable.

Default value: Not Selected  

Derive Schema from a Sample Size of*

Required

Select the size of the number of initial input documents to be used when deriving the schema to be added to the binary output header. The sizing that you choose depends on the uniformity of the source schema. For example, if the schema is uniform across the documents, then choose Small. If the schema differs from document to document, then choose a larger size (Medium or Large) to attain a more accurate sampling of your schema. The performance impact on the Pipeline execution/validation is greater, the larger the sample size is. If you select None, then the schema is not sampled.

Multiexcerpt include macro
nameSnap Execution
pageAnaplan Read

Multiexcerpt include macro
nameSnap_Execution_Introduced
pageAnaplan Read
Examples

On this Page

Table of Contents
maxLevel2
excludeOlder Versions|Additional Resources|Related Links|Related Information

Snap Type:

Transform

Description:

This Snap reads JSON document data from its input view, and formats and writes it as JSON binary data to its output view.  A schema file can also be attached to the Snap that allows it to share the schema with upstream Snaps like the Mapper Snap.  

Prerequisites:

None

Support and limitations:

Works in Ultra Pipelines if Format each document is selected. 

Account: 

Accounts are not used with this Snap.

Views:


InputThis Snap has exactly one document input view, where it gets the JSON document data to be formatted.
OutputThis Snap has exactly one binary output view, where it provides the JSON binary data stream.
ErrorThis Snap has at most one document error view and produces zero or more documents in the view.

 

Settings

Label 

Required. The name for the Snap. You can modify this to be more specific, especially if you have more than one of the same Snap in your Pipeline.
Schema

For uploading JSON schema files, this is helpful when the formatted JSON has to follow a certain schema. This is particularly useful when used with Mapper Snap, the schema from the JSON Formatter Snap will be back-propagated to the Mapper Snap. This is a suggestible property, click on the browse button to select file from your project folder.

Example: contact.schema

Default value: [None]


Note

The Pipeline should be validated once when the schema file has been uploaded in order for the schema to be visible in the upstream Snap.


Binary Header Properties

The properties to add to the binary document's header.  The properties in the header of a binary document can be accessed in expression properties of downstream Snaps.  For example, a 'content-location' property added to the header in this Snap can be referenced in the file name property of a File Writer snap with the expression: $['content-location'].  When this Snap is configured to output a single binary document, the headers are computed from the first input document.  When the "Format each document" option is enabled, the headers are computed separately for each binary output.

Expression

Enter the function to be used to transform the data such as combine, concat or flatten.

Default value: None

Target Path

Enter in the target JSON path where the value from the expression will be written.

Example: $person.firstname to write the field 'firstname' of the 'person' object.

Default value:  None

Content

The input object or field whose data must be written to the output stream. For example, $payload or $emp_salary. Use $ to write the entire data.

See Filtering Output Data Using the JSON Formatter Snap's Content Setting further in this page for filtering the input data based on the Content field.

Default value: $

Ignore empty stream


Required in Standard mode. The Ignore empty stream property specifies that an empty array will be written to the output view in case no documents were received on the input view (disabled).
Will write nothing to the output view in case no documents were received on the input view if the property is enabled 

Default value: Not Selected

Format each document


If enabled, the property defines that one binary output stream is created for every document on its input view. If disabled, will write one binary output stream for all documents on its input view which are enclosed by a JSON array element [ .. ]. See the example: Using JSON Formatter Snap to render outputs from Group By Snaps, for a simple but less frequent scenario.

Default value: Not Selected  

JSON lines


If selected, writes all documents to a single output file, with each document appearing as a single line followed by a new line. This field cannot be used with Pretty-print properties. See the example: Using JSON Formatter Snap to render outputs from Group By Snaps, for a simple but less frequent scenario.

Default value: Not selected  

Pretty-print


If enabled, formats the output to make it more readable/printable.

Default value: Not Selected  

Derive Schema from a Sample Size of*

Required

Select the size of the number of initial input documents to be used when deriving the schema to be added to the binary output header. The sizing that you choose depends on the uniformity of the source schema. For example, if the schema is uniform across the documents, then choose Small. If the schema differs from document to document, then choose a larger size (Medium or Large) to attain a more accurate sampling of your schema. The performance impact on the Pipeline execution/validation is greater, the larger the sample size is. If you select None, then the schema is not sampled.

Multiexcerpt include macro
nameSnap Execution
pageAnaplan Read


Multiexcerpt include macro
nameSnap_Execution_Introduced
pageAnaplan Read

Examples


Expand
titleUsing JSON Formatter Snap to render outputs from Group By Snaps

Using JSON Formatter Snap to render outputs from Group By Snaps

This example demonstrates how, effective 4.23 GA and onwards, you can use the JSON Formatter Snap to render groups data from upstream Snaps such as Group By Fields.

In a scenario where the JSON Formatter Snap needs to format groups in the incoming data, we can enhance Snap's output to have each group rendered as a separate output, where each line is a member of the group.

Image Added

The Group By Fields Snap is set to group the incoming data by $key with the Target field as $group.

Group By Fields SnapOutput

Image Added

Image Added

Notice that the incoming data is grouped by key in this output. 

JSON Formatter Snap

Image Added

Output

Image Added

When this groups of data is passed as an input to the JSON Formatter Snap, we can use the fields JSON lines and Format each document in unison and render the content $group to achieve an output with multiple documents each corresponding to one group (key1, key 2 and key3 in this example) and one line for each element in these groups (Content array).

Download this Pipeline


Expand
titleFiltering Output Data Using the JSON Formatter Snap's Content Setting

Filtering Output Data Using the JSON Formatter Snap's Content Setting

This example demonstrates how, effective 4.20 Patch transform8670 and onwards, you can use the JSON Formatter Snap to filter the input JSON data. 

Download the Sample Pipeline.

  1. Using the sample Pipeline shown above, generate a JSON document using the JSON Generator Snap.
  2. In the Mapper Snap, map the input fields: interface_id, failed_pipeline, target_url, and payload to the required output fields.
  3. In in the JSON Formatter Snap, in the Content field under Settings select $payload as the object to be included in the output.
  4. Select the JSON lines check box to ensure each record appears as a separate line in the output file.
  5. Provide the name of the file to write to in the File Writer Snap and save it.
  6. Validate and execute the Pipeline.

Current behaviorOld behavior

With Patch transform8670 onwards, the JSON Formatter Snap correctly acknowledges the Content field, irrespective of the JSON lines check box selection. So, in this example, the output would contain only the specified object’s data ($payload):

Prior to Patch transform8670, the JSON Formatter Snap would ignore the value in the Content field and write the entire input data to the output file if the JSON lines check box was selected, as shown in the image below:



Expand
title Passing the execution status code through Binary Header Properties of the JSON Formatter Snap

Passing the Execution Status Code through Binary Header Properties of the JSON Formatter Snap

In this pipeline, the pipeline execution status is routed to the error view, which is redirected to reflect on the browser using the Binary Header Properties of the  JSON Formatter Snap. This allows us to view the   status on the browser same as on the output view of the triggered pipeline. 

Note

This workaround of using the Binary Header properties is mainly useful when the user wants to view the exact execution status of the triggered task which may or may not be consistent with the status code otherwise reflected on the browser.


 

The JSON Formatter Snap passes the actual status code to the browser via the Binary Header Properties:

The status code (405) as retrieved from the pipeline is mapped to the response:

The JSON Formatter Snap passes the actual status code to the browser via the Binary Header Properties:

The status code (405) as reflected on the browser (Postman):

 




Expand
titleCreating file with header value in a specific location

Creating a File with Header Value in a Specific Location

In this pipeline, the JSON Formatter Snap, creates a file with a header value on a specified location. The metadata is passed to the File Writer Snap using the Binary Header and  the Content properties on the JSON Formatter Snap.

Image Modified

The JSON Generator Snap passes the values for the file and the records to be created.

Image Modified

The JSON Formatter Snap passes the metadata to the File Writer Snap.

Image Modified


The File Writer Snap creates the file "demo-" + $['content-location'] + ".json" on a specified content location.

The successful execution of the pipeline displays the below output preview:

Note the file headers created on the sldb location, and the files names as demo-abc.json and so on.

Image Modified


Expand
titleSchema suggest to upstream Snap

Schema Suggest to Upstream Snap

In the example pipeline, Basic Use Case_JSON Formatter Schema Property, the Mapper Snap is used to write employee data into a file. The input data has to cater to a specified JSON schema, to enable this the Schema property is configured with a schema file. this allows the user to see the schema of the target file in the Mapper Snap. 

The JSON Formatter Snap is configured in the following manner, the schema file contact.schema is uploaded in the Schema property:


The schema defined in the contact.schema file is shown below:


Below is the Mapper Snap's configuration, note the Target Schema and the Output preview data sections where the schema of the target file and the mapped data are shown:


When executed the input record from the Mapper will be mapped to the specified path based on the target schema and written into the target file.

Exported pipeline is available in the Downloads section below.


/wiki/spaces/SD/pages/1439181

Downloads

Attachments
patterns*.slp,*.zip

Insert excerpt
Transform Snap Pack
Transform Snap Pack
nopaneltrue