Key-value pairings for Sales Layer export

Hi all,

I have an export from Sales Layer which I am trying to sanitize by combining key-value pairings. The Sales Layer gives us different arrays which contain the data-schemas and the products but does not combine them automatically. For example, this is what Sales Layer exports:

"data_schema": {
        "products": [
            "STATUS",
            "ID",
            "ID_categories",
            "code",
            "family",
            "category",
            "name",
            "description_nl"
]
}

"data": {
        "products": [
            [
                "M",
                "305",
                "535",
                "107893",
                [
                    "EC000038"
                ],
                "IB-SUB167",
                "DURA, 01982-ES 80w 118 mm",
                "DURA, 01982-ES 80w 118 mm"
]
]
}

I am trying to combine these so the products get the correct key-value pairing. For example:

"data": {
        "products": [
            [
                "STATUS": "M",
                "ID": "305",
                "ID_categories": "535",
                "code": "107893",
               "family": [
                    "EC000038"
                ],
                "category": "IB-SUB167",
                "name": "DURA, 01982-ES 80w 118 mm",
                "description_nl": "DURA, 01982-ES 80w 118 mm"
]
]
}

Is there an easy way to do this?

Hi @j.wiegmann

Unfortunately, there is no quick way to achieve your objective.

I assume that you have the below entity:

{
    "data_schema": {
        "products": [
            "STATUS",
            "ID",
            "ID_categories",
            "code",
            "family",
            "category",
            "name",
            "description_nl"
        ]
    },
    "data": {
        "products": [
            [
                "M",
                "305",
                "535",
                "107893",
                [
                    "EC000038"
                ],
                "IB-SUB167",
                "DURA, 01982-ES 80w 118 mm",
                "DURA, 01982-ES 80w 118 mm"
            ],
            [
                "M",
                "305",
                "535",
                "107893",
                [
                    "EC000038"
                ],
                "IB-SUB167",
                "DURA, 01982-ES 80w 118 mm",
                "DURA, 01982-ES 80w 118 mm"
            ]
        ]
    }
}

You can follow the steps below using the current functionalities.

  1. Adjust the structure of the values to prepare for further transformation.

  2. Recursively copy the data schema to all of the products inside data.products.

  3. Use the combination of Execute entity transformers and Node, transform nodes to loop into the data.products array.

  4. Inside each loop, map the schema to the product values respectively. So, each value object will have a key and a value.

  5. Transform each value object to a key-value pair.

  6. Still inside the loop (node transformer), finally, clean up each object product by setting the “values” as the root object of each product.

You will have below entity as the final result.

{
  "data_schema": {
    "products": [
      "STATUS",
      "ID",
      "ID_categories",
      "code",
      "family",
      "category",
      "name",
      "description_nl"
    ]
  },
  "data": {
    "products": [
      {
        "STATUS": "M",
        "ID": "305",
        "ID_categories": "535",
        "code": "107893",
        "family": [
          "EC000038"
        ],
        "category": "IB-SUB167",
        "name": "DURA, 01982-ES 80w 118 mm",
        "description_nl": "DURA, 01982-ES 80w 118 mm"
      },
      {
        "STATUS": "M",
        "ID": "305",
        "ID_categories": "535",
        "code": "107893",
        "family": [
          "EC000038"
        ],
        "category": "IB-SUB167",
        "name": "DURA, 01982-ES 80w 118 mm",
        "description_nl": "DURA, 01982-ES 80w 118 mm"
      }
    ]
  }
}

Please let me know if this is not the result you expected.

2 Likes

Hey,
@j.wiegmann indeed just as @Gugi explained we have done the same.
Also not that pagination in Sales Layer will NOT send the data_schema on subsequent pages, so its best to save it to a storage and reuse it from there.

2 Likes

Thank you both. Yes this works the intended way!