1.5

Page 34
Standard Data mapping configuration option as seen in the
All in One
plugin.
JSON string
Alternatively, one could set the data source to the JSON string option. In web
environments, it is common to send and retrieve data from a server using an AJAX
request (typically invoke from within JavaScript). In this scenario, the data is often
exchanged in JSON format. JSON is short for JavaScript Object Notation. It is a way to
store information in a structured and easy to read format. It is often referred to as xml
without nodes and meant for exchanging data. The following shows a simple JSON
structure holding the first and last name of a person.
{
"first": "Peter",
"last": "Parker"
}
When the ‘keys’ in the above sample (e.g. first and last) have matching data fields
names, in our template the personalization scripts of the template will have access to
the data. The JSON string samples below show various techniques on how to
incorporate JSON data in your data source.
When selected, a text area is shown allowing the user to enter a JSON string.
The JSON string may contain variables, globals, job infos and lookups as seen in
the
Value
field of the
Set Job Info and Variables
plugin.
The user can use a single variable assuming that the respective variable contains
a JSON string.
In case the JSON string is not a valid JSON object, the plugin will error out with
an explicit message.
JSON string samples
A hard-coded JSON string:
{
"first":"Peter",
"last":"Parker",
"email":"pparker@localhost.com"
}
A JSON string with references to local variables and Job Info 2:
{
"first":"%{first}",
"last":"%{last}",
"email":"%2"
}
A JSON string containing a local variable and various lookups:
{
"jobid":"%{jobid}",
"account":"lookup(OLCS_jobs, account, jobid, '%{jobid}')",
"datafile_name":"lookup(OLCS_jobs, datafile_name, jobid, '%{jobid}')",
"pages":"lookup(OLCS_jobs, pages, jobid, '%{jobid}')",