0

I need to transform below Input JSON to output JSON and not sure about how to write spec for that output. compare filed values in JOLT transformation

Here is the input:

{
  "body": {
    "productConfigurations": [
      {
        "productConfiguration": {
          "selected": true,
          "productSpecification": {
            "id": "1776911"
          },
          "productOffering": {
            "id": "1777341"
          }
        }
      },
      {
        "productConfiguration": {
          "selected": true,
          "productSpecification": {
            "id": "247541"
          },
          "productOffering": {
            "id": "735501"
          }
        }
      },
      {
        "productConfiguration": {
          "productSpecification": {
            "id": "280801"
          },
          "productOffering": {
            "id": "735501"
          }
        }
      }
    ]
  }
}

expected output: I need to transform below Input JSON to output JSON and not sure about how to write spec for that output. compare filed values in JOLT transformation.

{
  "body": [
    {
      "id": "1777341",
      "products": [
        {
          "id": "1776911"
        }
      ]
    },
    {
      "id": "735501",
      "products": [
        {
          "id": "247541"
        },
        {
          "id": "280801"
        }
      ]
    }
  ]
}
0

1 Answer 1

2

You can use the following successive shift transformations

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            "*": {
              "productSpecification": {
                "id": "@(2,productOffering.&).products[].&"
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "$": "&1.id",
        "*": "&1.&"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": "body[]"
    }
  }
]

where the main idea is to determine the common id values of the productOffering attributes through use of "id": "@(2,productOffering.&).products[].&" nested within "productSpecification" tagged object.

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

This is failing when we have only one productConfiguration.
Yes, you're right @Sandy . The redundant step(the former third one) is removed. Btw, have you ever checked out the answer provided for your second question?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.