Broke nested JSON array with JOLT

I’m looking for breaking nested JSON file and try to flat it to fit into a SQL database.

Current JSON:

{
  "content": {
    "failedPerProductLineAndReason": {
      "Product1": {
        "Downsizing licenses is not allowed": 1
      }
    }
  }
}

Expected outcome:

{
  "ErrorType": "failedPerProductLineAndReason",
  "product": "Product1",
  "error": "Downsizing licenses is not allowed",
  "quantity": 1
}

Flat nested JSON file

>Solution :

Go inside the Downsizing licenses is not allowed and get its value by @ and get another keys you want by $

[
  {
    "operation": "shift",
    "spec": {
      "*": { // content
        "*": { // failedPerProductLineAndReason
          "*": { // Product1
            "*": { // Downsizing licenses is not allowed
              "$2": "ErrorType",
              "$1": "product",
              "$": "error",
              "@": "quantity"
            }
          }
        }
      }
    }
  }
]

Leave a Reply