Generic JSON Import Advanced Example

The following is an example of a complex import document and template that uses most of the features present in a Generic JSON template.

Using the Import Manager, this example demonstrates how to take a JSON input document to create a template, then modify the template to resolve errors and accurately read the input, and prepare the data for mapping.

Input Document

Copy the following text to a new file and save as a JSON file. Open Import Manager and select the file as the Data Source Filename and click 'Next.' Note that any number of additional items can be included by repeating the data within the Item tag.

Copy
{
    "Items": [
        {
        "EAN": 2700524977488,
        "PrimarySpecs": {
          "ProductInformation": {
            "General": {
              "ProductName": "AC-UZ444",
              "ConsumerShortDescription": "Active 3D Glasses",
              "AvailableFrom": "2015-01-01 00:00:00"
           }
        },
            "Variants": [
              {
                "Name": "Color",
                "Value": "Gray"
              },
              {
                "Name": "Battery",
                "Value": "C2"
              }
            ],
            "Manuals": [
              {
                "type": "ManualDE",
                "value": "Manual-9"
              },
              {
                "type": "ManualEN",
                "value": "Manual-10"
              }
              ]
            },
        "SyncProtocols": [
            "Acme",
            "Sony",
            "Sharp"
        ]
      }
    ]  
}

Creating a Template

To create a template from an import file, copy the source file and paste into the Sample field on the Import Manager's Select Format step. Then, remove any duplicate elements. Since there is only a single Item element in the example above, it can be pasted as-is.

Note: When creating a template from a source file, ensure all the included elements that must be handled are represented. Only instructions in both the document and the generic template are processed. Instructions that are not defined in the template are ignored.

Remove Redundant Elements

The source file includes redundant elements that should be removed to create a valid template. When duplicates exist, clicking the Sample reload button displays a message about sibling nodes with the same name:

Remove repetitions of the 'Variants', 'Manual', objects, and values in the SynchProtocols array until only one of each remains. The Sample field now displays the following:

Copy
{
    "Items": [
        {
        "EAN": 2700524977488,
        "PrimarySpecs": {
          "ProductInformation": {
            "General": {
              "ProductName": "AC-UZ444",
              "ConsumerShortDescription": "Active 3D Glasses",
              "AvailableFrom": "2015-01-01 00:00:00"
           }
        },
            "Variants": [
              {
                "Name": "Color",
                "Value": "Gray"
              }
            ],
            "Manuals": [
              {
                "type": "ManualDE",
                "value": "Manual-9"
              }
              ]
            },
        "SyncProtocols": [
            "Acme"
        ]
      }
    ]  
}

Add Record and Source Instructions

The source file includes actual data, but must include instructions to represent the data instead. To identify missing instructions, click the Sample reload button and a message is displayed about a missing record declaration:

Use the "[?Instruction?]: "[?Record?]" and "[?Source?]" instructions to handle all the cases where you need to extract one value.

Copy
{
    "Items": [
        {
        "[?Instruction?]": "[?Record?]",
        "EAN": "[?Source?]",
        "PrimarySpecs": {
          "ProductInformation": {
            "General": {
              "ProductName": "[?Source?]",
              "ConsumerShortDescription": "[?Source?]",
              "AvailableFrom": "[?Source?]"
           }
        },
            "Variants": [
              {
                "Name": "Color",
                "Value": "Gray"
              }
            ],
            "Manuals": [
              {
                "type": "ManualDE",
                "value": "Manual-9"
              }
              ]
            },
        "SyncProtocols": [
            "Acme"
        ]
      }
    ]  
}

Add Repeated Instruction

To review how each option affects the outcome, make the following updates in the Sample template and then click the Sample reload button to update the Conversion Preview.

For the "Variants" object, if we insert the "[?Source?]" instruction in the "Value" element as shown below, the result is the value for the first repetition, 'Gray.'

Copy
"Variants": [
   {
    "Name": "Color",
    "Value": "[?Source?]"
    }
  ]

To get values from both "Variants" elements, there are two options: MultiSource and Source / Repeated / SourceID.

To get the Value from each repetition and be able to map them all to a multi-valued attribute / multiple reference / links targets / data container rows for a column, we can use the "[?MultiSource?]" instruction.

Copy
"Variants": [
              {
                "Name": "Color",
                "Value": "[?MultiSource?]"
              }
            ]

To map the data to different attributes, as is the case in our example, where the Name value of each repetition identifies the attribute, use these instructions:

  • "[?Instruction?]": "[?Source?]"
  • one "[?Repeated?]" to indicate that "Variants" is a repeated element
  • one "[?SourceID?]" to indicate that the "Name" value is used as an identifier for each repetition
Copy
"Variants": [
              {
                "[?Instruction?]": "[?Repeated?]",                
                "Name": "[?SourceID?]",
                "Value": "[?Source?]"
              }
            ]

The Import Manager displays the column header for each element using the pattern [Identifier].[SourceTagName].

Add Repeated Instruction With a Filter

To review how each option affects the outcome, make the following updates in the Sample template, and then click the Sample reload button to update the Conversion Preview.

The repeated Manual element is handled differently since the type of identifier is an attribute.

Start by placing the "[?Source?]" instruction to the value:

Copy
"Manuals": [
              {
                "type": "ManualDE",
                "value": "[?Source?]"
              }
           ] 

To get values for all repetitions, use the "[?Instruction?]": "[?Repeated?]" instruction and also add an identifier instruction "[?SourceID?]".

Copy
"Manuals": [
              {
                "[?Instruction?]": "[?Repeated?]",
                "type": "[?SourceID?]",
                "value": "[?Source?]"
              }
            ]

To filter repeated elements so that only elements with specific identifiers are considered, add the identifier to the "[?Repeated?]" instruction. To get only 'ManualEN' data, update the template as follows.

Copy
"Manuals": [
              {
                "[?Instruction?]": "[?Repeated ManualEN?]",
                "type": "[?SourceID?]",
                "value": "[?Source?]"
              }
            ]

Add MultiSource Instruction

For the repeated "SyncProtocols" element there is no identifier, so use the "[?MultiSource?]" processing instruction. When this instruction is used, the "[?Repeated?]" instruction is not required.

Copy
"SyncProtocols": "[?MultiSource?]"

Now that all instructions have been added, the template is below.

Copy
{
    "Items": [
        {
        "[?Instruction?]": "[?Record?]",
        "EAN": "[?Source?]",
        "PrimarySpecs": {
          "ProductInformation": {
            "General": {
              "ProductName": "[?Source?]",
              "ConsumerShortDescription": "[?Source?]",
              "AvailableFrom": "[?Source?]"
           }
        },
            "Variants": [
              {
                "[?Instruction?]": "[?Repeated?]",
                "Name": "[?SourceID?]",
                "Value": "[?Source?]"
              }
            ],
            "Manuals": [
              {
                "[?Instruction?]": "[?Repeated?]",
                "type": "[?SourceID?]",
                "value": "[?Source?]"
              }
              ]
            },
        "SyncProtocols": "[?MultiSource?]"
      }
    ]  
}

Conversion Preview

Test the state of the Sample template to ensure that all data has been replaced with valid instructions.

Click the Sample reload button . The Conversion Preview area displays the results of the input document against the provided template.