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.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 theintern type, the second parameter does not contain a file but the technical name of the provided data.
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.
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.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.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.
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.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.Outputting floating-point numbers
EJD-SetRealOutputFormat() defines how many decimal places floating-point numbers are output with. Values from 0 to 6 are permitted.
Creating and modifying JSON
EJD-CreateNewData() creates an empty JSON object that you fill in the template.
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.
Building an array
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:Checking whether the modification succeeded
EJD-ModificationOK brackets on the success of the last modification and, as a single tag, outputs the error code.
Code 15 is not listed in the previous documentation but exists in the shop.
Inputting and outputting raw data
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.<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().
Related topics
- Guide: JSON interface
- Guide: href attribute
- Reference: DC- (loops)
- Reference: DC- (free parameters and session parameters)
