JSON snippets
JSON snippets are snippets that contain JSON data instead of text. Just like other types of snippets, JSON snippets are stored in the Snippets folder on the Resources pane, but their file name ends in .json.
This topic contains information that only applies to JSON snippets. If you want to know how to add an existing (remote) snippet to the resources, or how to create an empty JSON snippet, please see Snippets.
It is possible to open and edit any external JSON file in the Designer: select File > Open, select All files (*.*) as the file type and then select an HTML or JSON file.
Using a JSON snippet
Unlike HTML snippets, JSON Snippets cannot be inserted into the content directly, but they can be accessed via a script using the loadjson()
function.
To load a JSON snippet in script, use: loadjson(‘snippets/nameofthesnippet.json’)
.
For example:
var json_data = loadjson("snippets/snippet.json");
results.html(json_data.field1);
See also: Writing your own scripts and loadjson().
For an example in which JSON snippets are being used to localize a template, see this how-to: Localizing templates using json.