< Back
Print

Building JSON Target Keys

When building a JSON export, a textual representation of the intended JSON structure must be entered in the connector. These keys define the path to the JSON field where the data will be exported. The syntax for JSON target keys is as follows:

target-key|sub-target-key

The best way to understand this is through an example. Suppose we want to build the following JSON structure:

{
  "product": {
    "basicData": {
      "id": "PN-10254",
      "name": "Smart LED TV"
    }
  }
}

To achieve this, you would enter the following target keys:

product|basicData|id
product|basicData|name

The value “Smart LED TV” will be exported into the name field. In a production export, the id might vary for each product:

product|basicData|id
product|basicData|name

It is worth noting that you can use an infinite number of sub-target keys to define nested JSON structures. For example:

product|media|images|main

This would create the following JSON structure:

{
  "product": {
    "media": {
      "images": {
        "main": ""
      }
    }
  }
}

You can also use placeholders for dynamic values at any level of the JSON structure. For example:

product|basicData|id
product|basicData|name|{StoreView}

This would result in the following JSON:

{
  "product": {
    "basicData": {
      "id": "PN-10254",
      "name": {
        "en": "Smart LED TV",
        "de": "Smart LED TV",
        "fr": "Smart LED TV"
      }
    }
  }
}

StoreView is a pre-defined placeholder that dynamically fills the language attribute based on the current store view.

Handling Language-Dependency in Sub-Arrays

(Only in the DynamicJSON Connector)

One of the key differences between the GenericJSON and DynamicJSON connectors is that the latter supports any JSON structure and enables you to position the language layer flexibly.

Example target key:

product|name|{StoreView}

This places the language layer last, so the result is this:

{
  "product": {
    "name": {
      "en": "Smart LED TV",
      "de": "Smart LED TV",
      "fr": "Smart LED TV"
    }
  }
}

All connectors share a same behavior. If a target key is the same, it will be overwritten each time the processing logic reaches it. This means that in this case if we enter a target key like product|longDescription French “wins” since it is the last language and the French text will be exported in that key. As shown in the previous examples this can be avoided by placing {StoreView} in the key.

However there is a use case in which the language layer is set in deeper sub-configurations. Let’s have a look at this example.

Here I am building a loop of attributes in the target key attributesLoop.

Each attribute shall be a sub-object with a name and a value|{StoreView} because the value is language-dependent. So my consecutive formats look like this.

The issue now is that only the last language would be included in the export since the basic target key is just attributesLoop and the last language wins.

This can be avoided by adding the virtual sub-target key [replace_recursive], changing my target key to attributesLoop|[replace_recursive]. This signals the connector that the connector that the values of each language shall be merged instead of replaced.

The export in my example looks like this.

{
  "attributesLoop": [
    {
      "name": "teaser",
      "value": {
        "en": "Bold flavor, rich aroma – our finest brew in every cup.",
        "de": "Kräftig im Geschmack, aromatisch im Duft – unser bester Kaffee für jeden Moment.",
        "fr": "Saveur intense, arôme raffiné – le meilleur de notre café dans chaque tasse."
      }
    },
    {
      "name": "description",
      "value": {
        "en": "Barissimo Unser Bester is a full-bodied and aromatic coffee blend crafted for true coffee lovers. Expertly roasted to perfection, it delivers a balanced, characterful taste that awakens your senses from the first sip.",
        "de": "Barissimo Unser Bester ist eine charaktervolle und aromatische Kaffeemischung, perfekt für Genießer. Sorgfältig geröstet entfaltet er ein vollmundiges Aroma und einen ausgewogenen Geschmack, der jeden Schluck zu einem Genuss macht.",
        "fr": "Barissimo Unser Bester est un café riche et aromatique, soigneusement torréfié pour révéler tout son caractère. Son goût équilibré et sa profondeur en font le compagnon idéal pour les vrais amateurs de café."
      }
    },
    {
      "name": "usps",
      "value": {
        "en": "coffee,black",
        "de": "coffee,black",
        "fr": "coffee,black"
      }
    }
  ]
}
Was this article helpful?
How can we improve this article?
Please submit the reason for your vote so that we can improve the article.
Table of Contents