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 Task 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, $group$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 Snap creates one binary output stream is created for every document on its input view. If disabled, will write it writes one binary output stream for all documents on its input view which are enclosed by a JSON array element [ .. ]. See  See the example: Using  Using JSON Formatter Snap to render outputs from Group By Snaps, for a simple but less-frequent scenario.

Info
titleFor Data Groups in Input View

Select this check box along with JSON lines check box and set the Content field to $group to output one document per group with member in the group as a separate JSON line.

Default value: Not Selected selected  

JSON lines


If selected,  writes the Snap 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 check boxSee the example: Using JSON Formatter Snap to render outputs from Group By Snaps,  for for a simple but less-frequent scenario.

Info
titleFor Data Groups in Input View

Select this check box along with Format each document check box and set the Content field to $group to output one document per group with each member in the group as a separate JSON line.

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
title

Using 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

 you can use the JSON Formatter Snap to render groups data from upstream Snaps such as Group By Fields Snap.

In a scenario where the JSON Formatter Snap needs to format

groups in the incoming data

data groups, we can enhance

Snap

the Snap's output to

have

format each group

rendered

as a separate

output

document, where each line is a member of the group.

Image Modified

We use the JSON Generator Snap to pass the raw JSON content to be formatted.

JSON Generator SnapOutput (JSON content to be formatted)

Image Added

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 (Raw JSON rendered into groups)

Image Modified

Image Modified

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

JSON Formatter Snap

Image Modified

Output (one document per group and one line per group member)

Image Modified

When this groups of data is passed as an input to the

When the JSON Formatter Snap received data groups, we can

use

select the fields JSON lines and Format each document

 in

 check boxes in unison and

render

the Snap formats the content

$group to achieve an output with

as multiple documents

each corresponding to one group

– one per group (key1, key 2 and key3 in this example)

and

with one line for each element in these groups

(Content array)

.

Download this Pipeline

ExpandtitleFiltering 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.

Image Modified

  1. Using the sample Pipeline shown above, generate a JSON document using the JSON Generator Snap.
    Image Modified
  2. In the Mapper Snap, map the input fields: interface_id, failed_pipeline, target_url, and payload to the required output fields.Image Modified
  3. In in the JSON Formatter Snap, in the Content field under Settings select $payload as the object to be included in the output.
    Image Modified
  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):

Image Modified

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:

Image Modified

Expandtitle

Passing the

execution status code through Binary Header Properties of the JSON Formatter SnapPassing 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.


Image Modified 

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

Image Modified

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

Image Modified

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

Image Modified

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

 Image Modified

Expandtitle

Creating

file with header value in a specific locationCreating

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.

Image Modified

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

ExpandtitleSchema 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. 

Image Modified

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

Image Modified


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

Image Modified


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:

Image Modified

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.

Image Modified

Exported pipeline is available in the Downloads section below.

Additional Example: Writing the Results of a Twitter Query to a File

Downloads

Attachments
patterns*.slp,*.zip

Excerpt Include
Transform Snap Pack
Transform Snap Pack
nopaneltrue