...
In this article
Table of Contents | ||
---|---|---|
|
...
Snap type:
Read
...
Description:
...
|
Overview
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]
...
Works in Ultra Pipelines.
...
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.
Prerequisites
None.
Support for Ultra Pipelines
- Works in Ultra Pipelines.
See Snap Support for 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/Output | Type of View | Number of Views | Examples of Upstream and Downstream Snaps | Description |
---|---|---|---|---|
Input | Document |
|
| This Snap can have an upstream Snap that can pass a JSON document in output view. |
Output | Document |
|
| This Snap generates a document that contains the expected result along with the original JSON document (when Pass through is enabled). |
Snap Settings
Parameter Name | Data Type | Description | Default Value | Example | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Label | String |
| N/A | JSON Generator | ||||||||
Edit JSON | Apache Velocity template | Optional. Launches the JSON editor which will allow defining JSON. The editor will load an existing JSON document if it was defined previously. The editor lets you save JSON in SnapLogic's file system or import existing JSON documents from it. Note that this 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. |
...
For more information |
...
Process array
...
, see | Empty JSON file | File with JSON content |
Process Array | Check box | Optional. 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
...
Selected | Selected | ||||
Pass through | Check box | Optional. 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. | Deselected | Selected | |
|
...
| String | Indicates how the Snap must be executed. Available options are:
| Validate & Execute | Execute only |
Troubleshooting
Error | Reason | Resolution |
---|---|---|
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
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 having:
...
- Static content that produces one output document
...
- OR
- 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
...
- Variables in the JSON, which can be substituted with document values from the input view
...
- of the Snap.
...
Escaping Special Characters
Additionally, some
...
special characters can be escaped using the following notations.
Type | To pass this value | Specify |
---|---|---|
Single characters | $ | #[ |
...
$]# or \$ | ||
JSON String | ## | #[##]# |
For
...
information on how to use pipeline parameters and field values within this Snap, see the "Velocity Templates in Generator Snaps" section of Parameters and Fields.
Examples
Using the Pass Through Functionality
Consider the following Pipeline that combines two simple datasets.
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) | |
---|---|
Input JSON | Output JSON |
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) | |
---|---|
Input JSON | Output JSON |
The output JSON contains:
- Data from the input document.
- Data captured from the upstream parameter.
Downloads
Note | ||
---|---|---|
| ||
|
Attachments | ||
---|---|---|
|
Insert excerpt | ||||||
---|---|---|---|---|---|---|
|
...