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

Jolt transformation to remove nested array

Could you please assist me in performing a Jolt transformation to convert the JSON structure provided below into the desired output format? I would greatly appreciate your guidance or a sample transformation specification that achieves this conversion. Thank you!
From JSON :

[
  {
    "doc_GUID": "ae5deb48-9807-11ef-aaeb-ec2a723f4399",
    "items": [
      {
        "item_id": "00-00002475",
        "type_of_goods": "RR"
      },
      {
        "item_id": "00-00001243",
        "type_of_goods": "TT"
      },
      {
        "item_id": "00-00002997",
        "type_of_goods": "AA"
      }
    ]
  },
  {
    "doc_GUID": "e83f9131-a034-11ef-aaeb-ec2a723f4399",
    "items": [
      {
        "item_id": "00-00002828",
        "type_of_goods": "YY"
      },
      {
        "item_id": "00-000029971",
        "type_of_goods": "EE"
      }
    ]
  }
]

To this result:


[
  {
    "doc_GUID": "ae5deb48-9807-11ef-aaeb-ec2a723f4399",
    "item_id": "00-00002475",
    "type_of_goods": "RR"
  },
  {
    "doc_GUID": "ae5deb48-9807-11ef-aaeb-ec2a723f4399",
    "item_id": "00-00001243",
    "type_of_goods": "TT"
  },
  {
    "doc_GUID": "ae5deb48-9807-11ef-aaeb-ec2a723f4399",
    "item_id": "00-00002997",
    "type_of_goods": "AA"
  },
  {
    "doc_GUID": "e83f9131-a034-11ef-aaeb-ec2a723f4399",
    "item_id": "00-00002828",
    "type_of_goods": "YY"
  },
  {
    "doc_GUID": "e83f9131-a034-11ef-aaeb-ec2a723f4399",
    "item_id": "00-000029971",
    "type_of_goods": "EE"
  }
]

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

>Solution :

You can loop within the objects of the items array while bringing the doc_GUID attribute from two upper level such as :

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "items": {
          "*": {
            "@2,doc_GUID": "&3_&1.doc_GUID",
            "*": "&3_&1.&"
          }
        }
      }
    }
  },
  { //get rid of the object keys
    "operation": "shift",
    "spec": {
      "*": "[]"
    }
  }
]

the demo on the site Jolt Transform Demo Using v0.1.1 is :

enter image description here

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