0

In SnapLogic, is there is simple way to take the first JSON record and produce the output that is shown afterwards?

This is a simplified version of what is trying to be achieved...

The input record contains two variables and an array of "skus" consisting of items with two variables, a "skucode" and a "shade".

Each output record is a superset of the input record. Each output record promotes one of the array items above the array to the same level as the two variables in the input record, as shown in the example below.

Input:

{
  "code": "ABCD",
  "name": "Product A",
  "sku": [
    {
      "skucode": "ABCD12",
      "shade": "green"
    },
    {
      "skucode": "ABCD13",
      "shade": "brown"
    },
    {
      "skucode": "ABCD14",
      "shade": "blue"
    },
    {
      "skucode": "ABCD15",
      "shade": "red"
    },

  ]
}

Output:

[{
  "code": "ABCD",
  "name": "Product A",
  "skucode": "ABCD12",
  "shade": "green"
  "sku": [
    {
      "skucode": "ABCD12",
      "shade": "green"
    },
    {
      "skucode": "ABCD13",
      "shade": "brown"
    },
    {
      "skucode": "ABCD14",
      "shade": "blue"
    },
    {
      "skucode": "ABCD15",
      "shade": "red"
    },

  ]
},

{
  "code": "ABCD",
  "name": "Product A",
  "skucode": "ABCD13",
  "shade": "brown"
  "sku": [
    {
      "skucode": "ABCD12",
      "shade": "green"
    },
    {
      "skucode": "ABCD13",
      "shade": "brown"
    },
    {
      "skucode": "ABCD14",
      "shade": "blue"
    },
    {
      "skucode": "ABCD15",
      "shade": "red"
    },

  ]
},
{
  "code": "ABCD",
  "name": "Product A",
  "skucode": "ABCD14",
  "shade": "blue"
  "sku": [
    {
      "skucode": "ABCD12",
      "shade": "green"
    },
    {
      "skucode": "ABCD13",
      "shade": "brown"
    },
    {
      "skucode": "ABCD14",
      "shade": "blue"
    },
    {
      "skucode": "ABCD15",
      "shade": "red"
    }
  ]

},
{
  "code": "ABCD",
  "name": "Product A",
  "skucode": "ABCD15",
  "shade": "red"
  "sku": [
    {
      "skucode": "ABCD12",
      "shade": "green"
    },
    {
      "skucode": "ABCD13",
      "shade": "brown"
    },
    {
      "skucode": "ABCD14",
      "shade": "blue"
    },
    {
      "skucode": "ABCD15",
      "shade": "red"
    }
  ]
}
]
CCELC
  • 1
  • 1
  • We're quite new to SnapLogic and assumed there would be a simple way to implement this pattern but couldn't find one in the documentation. – CCELC Feb 20 '19 at 13:24

1 Answers1

0

The simplest solution off the top of my head would be something as follows:

Sample Pipeline:

Sample Pipeline

Input (JSON Generator):

Input

Mapping before JSON splitter:

mapper

JSON splitter:

JSON splitter

Mapping after JSON splitter:

mapper 2

Output:

output

Note: Instead of directly using $sku in the include path, I first stringified the JSON into a new field and then added it in the include path list. This is because you cannot include the path you are splitting. For the final desired result, I just parsed the JSON text into a JSON again.

I hope this is what you guys need :)

Bilesh Ganguly
  • 3,792
  • 3
  • 36
  • 58