Versions Compared

Key

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

...

Snap type:

Read

...

Description:

...

In this article

Table of Contents
maxLevel2
absoluteUrltrue

Overview

You can use this Snap to generate a JSON document for the next Snap in the

...

Pipeline.

...

  • This Snap is often used at the beginning of a

...

  • Pipeline to create a file.

...

[None]

...

...

Accounts are not used with this Snap.

...

This Snap has at most one document error view and produces zero or more documents in the view.

If the Snap fails with an error in the JSON, an error document is sent to the error view containing the fields error, original, and templateOutput:

Code Block
{
    "error": "Unexpected character ('{' (code 123)): was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name\n at [Source: JSON Generator; line: 4, column: 2]",
    "original": null,
    "templateOutput": "\n[\n    {\n{\n    }\n]\n\n\n"
  }

...

Settings

Label

...

Edit JSON

...

  • This Snap does not need any Accounts.

Image Added

Prerequisites

None.

Support for Ultra Pipelines

Works in Ultra Pipelines

Limitations and Known Issues

The maximum size for a JSON file generated using this Snap is 16 MB.

Snap Input and Output

Input/OutputType of ViewNumber of ViewsExamples of Upstream and Downstream SnapsDescription
Input 

Document


  • Min: 0
  • Max: 1
  • Mapper Snap
  • Copy Snap
  • Splitter Snap
This Snap can have an upstream Snap that can pass a JSON document in output view. 
Output

Document

  • Min: 1
  • Max: 1
  • Mapper Snap
  • Copy Snap
  • JSON Parser
  • JSON Formatter

This Snap generates a document that contains the expected result along with the original JSON document (when Pass through is enabled).

Snap Settings

Parameter NameData TypeDescriptionDefault ValueExample 
LabelString
Insert excerpt
File Writer
File Writer
nopaneltrue
N/AJSON Generator
Edit JSONApache Velocity template

Optional. Launches the JSON editor which allows you to define JSON. The editor loads an existing JSON document if defined previously. The editor lets you save JSON in SnapLogic's file system or import existing JSON documents from it

...

.

You can substitute the variables in the JSON with document values from the input view of the Snap.

Info
The JSON text is treated as an Apache Velocity template, so you can substitute values from input documents or the pipeline parameters. The Apache Velocity

...

template can be used to pass dynamic values from upstream Snaps.

...

Process array 

...

 

You can customize the JSON file to: 

  • Generate static content that produces one output document.

  • Generate a list of static documents within an array definition which can then be transformed into multiple documents upstream by using a JSON Splitter Snap.

Learn more:

Empty JSON fileFile with JSON content
Process ArrayCheckboxOptional. The Process array property specifies whether or not the Component should take a root JSON array and

...

write each element of the array as a JSON document. 

...

Example: Selected 

Default value: Selected 

Clicking Edit JSON will launch the JSON Editor. The JSON will be stored in the Snap (after clicking OK). The JSON can be exported to SnapLogic's file system using the export action or be imported from there using the import action.
 
The JSON can be customized to meet specific needs, such as: 
1) having static content that produces one output document or  

2) having a list of static documents within an array definition which can then be transformed into multiple documents upstream by using a JSON Splitter Snap or 

 Image Removed

 
3) having variables in the JSON, which can be substituted with document values from the input view of
the Snap. 

Additionally, some of the characters can be escaped using #[]# (for a JSON string) or \ (for a single character):

  • For example, to escape ##, you specify #[##]#
  • For example, to escape $, you specify #[$]# or \$

...

SelectedSelected
Pass throughCheckboxOptional. Use this property to pass the data in the input document through to the output document and merge it under the key 'original'. See example for more details.DeselectedSelected
Support Type ExtensionsCheckbox
Multiexcerpt include macro
nameME_Support_Type_Extensions
pageJSON Formatter
DeselectedSelected
Snap ExecutionString

Indicates how the Snap must be executed. Available options are:

  • Validate & Execute: Performs limited execution of the Snap (up to 50 records) during Pipeline validation; performs full execution of the Snap (unlimited records) during Pipeline execution.
  • Execute only: Performs full execution of the Snap during Pipeline execution; does not execute the Snap during Pipeline validation.
  • Disabled: Disables the Snap and, by extension, its downstream Snaps.

Validate & ExecuteExecute only

Troubleshooting

ErrorReasonResolution
Unexpected character ('{' (code 123)

The array entries in the JSON file do not follow the syntax. A comma ',' is expected before the beginning of every second array—'{'.

Verify the array at the row and column mentioned beside the error message using the Edit JSON feature and add a comma appropriately.

Editing JSON document

  1. Click Edit JSON to launch the JSON Editor. 

  2. Edit the JSON file as required.

  3. Click Ok.
    The JSON document is stored in the Snap.

Options in JSON Editor

Image Added

The following table describes the numbered callouts in the image:

Callout Number

Option

Description

1

Hide whitespace

Hides the whitespace in the output that you may have in the JSON input document.

2

Format code

Allows you to format the JSON input document.

3

Export

Export the JSON document to SnapLogic's file system (SLFS)

4

Import

Import a JSON document from your local directory or SLFS.


Escaping Special Characters

Additionally, some special characters can be escaped using the following notations.

Type To pass this valueSpecify
Single characters
$
#[$]# or \$
JSON String
##
#[##]#

For information on how to use pipeline parameters and field values within this Snap, see

...

Velocity Templates in Generator Snaps

...

in Parameters and Fields.

Examples


Using the Pass Through Functionality

Consider the following Pipeline that combines two simple datasets.

Image Added

Download this Pipeline

Snap Configurations

JSON Object (JSON Generator Snap with Pass through disabled)

This JSON Generator Snap, JSON Object, is used as an input by the downstream JSON Generator Snap, Combined JSON.

Snap Configuration (JSON Object)
Image Added
Input JSONOutput JSON
Image Added
Image Added

Combined JSON (JSON Generator Snap with Pass through enabled)

  • The Pass through check box is selected.
  • In addition to this, the upstream parameter, $details.username, is included in this Snap's JSON script to capture information based on the username field in the upstream document.
Snap Configuration (Combined JSON)

Image Added

Input JSONOutput JSON
Image Added
Image Added

The output JSON contains:

  • Data from the input document.
  • Data captured from the upstream parameter.

Input Schema Types

This example Pipeline demonstrates the difference in the input schema types on selecting and deselecting Support Type Extensions checkbox.
Image Added

There is no difference in the preview output of JSON Generator or JSON Parser as the JSON representation remains the same. But the Mapper Snaps downstream of the JSON Generator Snap shows the difference in the Input Schema types.

The input schema in Mapper Snap when you deselect Support Type Extensions checkbox in the JSON Generator Snap is as follows. The Snap displays the SnapLogic-specific syntax in the Input Schema.
Image Added

Here's the same Mapper Snap when you select the Support Type Extensions checkbox. Note the data types in the Input Schema—the Snap does not display the SnapLogic-specific syntax in the Input Schema.
Image Added


Similarly, here's a Mapper Snap showing the JSON Parser output when you deselect the Support Type Extensions checkbox.
Image Added

Here's the same Mapper when you select the Support Type Extensions checkbox.
Image Added

The Support Type Extensions state affects the JSON Formatter's output. When you deselect this checkbox, the SnapLogic-specific syntax is not used; the Snap uses a string representation for each of the special objects.
Image Added

Here's the output when you select the Support Type Extensions checkbox:
Image Added

Downloads

Note
titleImportant Steps to Successfully Reuse Pipelines
  1. Download and import the Pipeline into SnapLogic.
  2. Configure Snap accounts as applicable.
  3. Provide Pipeline parameters as applicable.

Attachments
patterns*.slp, *.zip


Insert excerpt
Transform Snap Pack
Transform Snap Pack
nopaneltrue

...

See Also