Skip to main content
With the JSON interface, a template brings data into the shop that does not come from the product data: a nutrition table per item, sales figures for the signed-in customer, the response of a payment service provider. Conversely, it also builds JSON that the shop passes on to a tracking or external system. The tags with the prefix EJD- (External JSON Data) give you access to this. They cover three tasks. Guide: JSON interface

The process

Every access runs in three steps: load, check, access. When loading, the data gets a freely chosen ID by which all further tags find it again.
Several JSON data sets can be kept loaded at the same time. The ID keeps them apart. That is why every access tag carries the ID as its last parameter, and EJD-SetUseID() saves you from repeating it every time.
The examples on this page refer to this file:

Loading data

The type

With the subshop type, the shop selects the matching subdirectory itself. In the English subshop, ~EJD-LoadData(subshop,file.json,jdat)~ therefore loads the file /English/file.json. The same line in the template thus works in all subshops.

The path with the “intern” type

With the intern type, the second parameter does not contain a file but the technical name of the provided data.
In addition, individual modules provide their responses.
The last three are not listed in the previous documentation but exist in the shop. Further names are added with new modules; ask WEBSALE AG or the respective service provider about them.
With internal data, you often do not know in advance which fields will be delivered. EJD-RawDataOutput() outputs the complete data set and is the fastest way to get an overview.

Checking whether loading succeeded

EJD-DataOK() brackets on success. As a single tag, it outputs the error code.
EJD-DataOK() always needs the ID written out. EJD-SetUseID() has no effect here, since it only appears inside the bracket itself.

Setting the ID once

EJD-SetUseID() defines the ID that all subsequent access tags use if they are not given one themselves.
For all access, check and modification tags, the ID is therefore optional. The previous documentation lists it as a mandatory parameter on the individual pages. It is only necessary if no default ID is set or if you switch between several data sets.
The default ID can be set again as often as you like. With several data sets loaded at the same time, you use it to switch back and forth.

The access path

All access tags expect the path to the element as their first parameter.
Array elements are counted from 0. The first element is [0]. That is why DC-ZeroLoopX is a better fit as a loop over an array than DC-LoopX, which counts from 1.

Reading values

As an area tag, EJD-DA-ArrayElements() only applies if the element really is an array and is not empty. The bracket thus answers in one step whether a loop is worthwhile at all.

Checking the type of a value

JSON has several value types. Eight area tags check which one is present.
The eight check tags are pure area tags. Written as a single tag, they have no effect.
With third-party data, type checking is worthwhile. A field that was a number yesterday and is null today otherwise leaves an unchecked output empty.

Reusing values

The access tags carry parameters. This means they cannot be written as $…$ in another tag, because tag-in-tag only works with single tags without their own argument. That is why the shop remembers the addressed name and value with every access. Two parameterless tags output them again. EJD-DA-TouchName(), EJD-DA-TouchValue() and EJD-DA-TouchArrayElements() exist only for this purpose: they remember something without outputting anything themselves.
Output:
This is the standard pattern for arrays: remember the count, set up a counting loop with it, and insert the position as the index. DC-ZeroLoopX counts from 0 and thus matches the array indexes exactly.
Reference: DC- (loops)

Iterating over elements

For an object whose keys you do not know, a counting loop does not help. EJD-ElementIterator() instead runs over the children of an element and outputs their names.
As a single tag inside the loop, EJD-ElementIterator outputs the name of the current element. Because it is then parameterless, it can be inserted into the access path as $EJD-ElementIterator$. The pattern above is based on exactly this.
The loop can be nested, but only up to a fixed depth of ten levels. If this is exceeded, the shop writes a critical error to the log and the loop does not start.

Outputting floating-point numbers

EJD-SetRealOutputFormat() defines how many decimal places floating-point numbers are output with. Values from 0 to 6 are permitted.
A value outside 0 to 6 makes the tag invalid; the previous setting then remains in place. The setting applies from the point in the template at which it is set, and for all loaded data sets.

Creating and modifying JSON

EJD-CreateNewData() creates an empty JSON object that you fill in the template.
Output:
All these tags work not only on newly created data but also on loaded data. This lets you enrich a file you have read in within the template and then pass it on.
If the path already exists, the previous value is replaced. If it does not exist yet, it is created, provided the parent element exists. EJD-DA-ArrayExtend() and EJD-DA-DeleteElement(), on the other hand, do not create anything: if their path leads nowhere, they report an error.
The root element can only be turned into an object or an array. Any attempt to give it a simple value ends with error code 14.

Building an array

Output:
If the root element itself is to be an array, specify _root_ as the path: ~EJD-DA-SetToEmptyArray(_root_,jdat)~ results in [].

An example from tracking

Build a JSON with the index and price of all displayed products on the product overview page:
Turn off price formatting before you pass a price as a number. Otherwise, it arrives with thousands separators and a decimal comma and is truncated when converted to a number.

Checking whether the modification succeeded

EJD-ModificationOK brackets on the success of the last modification and, as a single tag, outputs the error code.
The error code persists even if the next modification succeeds. Therefore, reset it after every check with EJD-ResetModificationOK; otherwise, all subsequent checks report the same old error.
Code 15 is not listed in the previous documentation but exists in the shop.

Inputting and outputting raw data

The two input tags belong together with the matching name when loading: EJD-SetRawDataInput() with rawdatainput, EJD-SetRawDataHexCodedInput() with rawdatahexcodedinput. If they are mixed up, the interface delivers unusable data because hex-encoded characters are read as plain text or vice versa.
EJD-RawDataOutput() outputs the data without HTML encoding. This is intentional so that valid JSON is produced, but it makes the tag dangerous for third-party data. Never use it to write unchecked third-party data into the visible page content. For debugging, put the output in an HTML comment; in live operation, put it in a script element or an interface.

Generating a JSON Web Token

EJD-GenerateJWT() signs the loaded JSON data and outputs it as a JSON Web Token. This lets you pass data to an external system in a tamper-proof way.
This tag is not described in the previous documentation but exists in the shop. The secret for the signature is the same configuration entry that DC-FPX_hash() and DC-FPX_encrypt() also use.
Reference: <DesignControl> section

The tags at a glance

All tags are permitted on all templates. The ID is optional for all tags once it has been set with EJD-SetUseID(), with the exception of EJD-DataOK() and EJD-RawDataOutput().
  • Guide: JSON interface
  • Guide: href attribute
  • Reference: DC- (loops)
  • Reference: DC- (free parameters and session parameters)