Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{
  "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"
            }
          }
        }
      }
    }
  }
]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading