Developer forum

Forum » Integration » JSON import of products and variants fails

JSON import of products and variants fails

Michael Knudsen
Reply

Hello forum,

- having a DW9.10.14 to import a JSON file will fail, if not all "EcomProducts" fields are present on the variant. In this ex. "unitprice" + "unitcurrency" are only relevant for the product.

Log:
Import job failed: The source reader for the table: [EcomProducts] can not get a value for the column: [unitprice].The input row is:...

Is there anyway I can bypass the requirement for adding the fields to the variant?

 

PS. Doing the same with a XML file will work fine.

 

Below is a snippet of the JSON:

    {
        "tableName": "EcomProducts",
        "EcomProducts": [
            {
                "productid": "ZXY111",
"productvariantid": "",
                "productlanguageid": "LANG1",
                "productdefaultshopid": "",
                "productnumber": "ZXY111",
                "productname": "Chair (product)",
                "unitprice": "357.00",
                "unitcurrency": "EUR"
            },
            {
                "productid": "ZXY111",
"productvariantid": "fabric_643.cover_oak.base_black",
                "productlanguageid": "LANG1",
                "productdefaultshopid": "",
                "productnumber": "ZXY111",
                "productname": "Chair (variant)"
            }
        ]
    }
 
Br. Michael Knudsen

Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply
This post has been marked as an answer

Hi Michael,
it works in the XML Provider because of the differences in the implementation in those two providers. The XML provider auto fills the not present columns with a null value,
but this is not implemented in the JSON provider. As a workaround you can try to use JSON->XML provider job and then use XML Provider->Your destination provider job
or implement a custom table script that can add the missed row column values at the runtime and use that table script in the JSON -> Your destination provider job.
You can read more about Table Script implementation here.
The sample pseudo code that can fill the missed columns may look like this:
 foreach (ColumnMapping cm in mapping.GetColumnMappings().Where(cm => cm != null && cm.Active && cm.SourceColumn != null))
                {
                    if (!row.ContainsKey(cm.SourceColumn.Name))
                    {
                        row.Add(cm.SourceColumn.Name, null);
                    }
                }
BR, Dmitrij

Votes for this answer: 1
 
Michael Knudsen
Reply

Thanks for your feedback Dmitrij, think the way forward is the Table Script implementation, but it would have been lovely, if XML and JSON provider followed the same implementation.

Br. Michael Knudsen

 

You must be logged in to post in the forum