简体   繁体   中英

Jolt JSON transformation

I want to transform this JSON:

{
  "_id": "6218e53465793fa20ea11524",
  "patientorderitems": [
    {
      "poi_id": "6218e53465793fa20ea1152a",
      "patientorderlogs": [
        {
          "pol_id": "6218e53465793fa20ea1152e",
          "useruid": "61ee4995f16eebb6b7e1c644",
          "modifiedat": "2022-02-25T17:18:28Z"
        },
        {
          "pol_id": "6218e53465793fa20ea1152c",
          "useruid": "61ee4995f16eebb6b7e1c643",
          "modifiedat": "2022-02-25T17:18:28Z"
        }
      ]
    },
    {
      "poi_id": "6218e53465793fa20ea11525",
      "patientorderlogs": [
        {
          "pol_id": "6218e53465793fa20ea11529",
          "useruid": "61ee4995f16eebb6b7e1c644",
          "modifiedat": "2022-02-25T17:18:28Z"
        }
      ]
    }
  ]
}

To this JSON:

[
  {
    "_id": "6218e53465793fa20ea11524",
    "poi_id": "6218e53465793fa20ea1152a",
    "pol_id": "6218e53465793fa20ea1152e",
    "useruid": "61ee4995f16eebb6b7e1c644",
    "modifiedat": "2022-02-25T17:18:28Z"
  },
  {
    "_id": "6218e53465793fa20ea11524",
    "poi_id": "6218e53465793fa20ea1152a",
    "pol_id": "6218e53465793fa20ea1152c",
    "useruid": "61ee4995f16eebb6b7e1c643",
    "modifiedat": "2022-02-25T17:18:28Z"
  },
  {
    "_id": "6218e53465793fa20ea11524",
    "poi_id": "6218e53465793fa20ea11525",
    "pol_id": "6218e53465793fa20ea11529",
    "useruid": "61ee4995f16eebb6b7e1c644",
    "modifiedat": "2022-02-25T17:18:28Z"
  }
]

I am currently using this specification and it not work for me:

[
  {
    "operation": "shift",
    "spec": {
      "patientorderitems": {
        "*": {
          "patientorderlogs": {
            "*": {
              "@(4,_id)": "[&3]._id",
              "@(2,poi_id)": "[&3].poi_id",
              "pol_id": "[&3].pol_id",
              "useruid": "[&3].useruid",
              "modifiedat": "[&3].modifiedat"
            }
          }
        }
      }
    }
  }
]

Can some one give a specification for this please and is there any clear documentation for jolt JSON

.................................................................... ............................................................

One more level of node is needed. For this aim, you can prepend all values of the innermost attributes by &1. .

Then an extra shift transformation is added to remove unwanted key names and square brackets wrapping the objects.

So, you can use the following specs:

[
  {
    "operation": "shift",
    "spec": {
      "patientorderitems": {
        "*": {
          "patientorderlogs": {
            "*": {
              "@(4,_id)": "&1.[&3]._id",
              "@(2,poi_id)": "&1.[&3].poi_id",
              "*": "&1.[&3].&" // combine all innermost attributes by "*" wildcard
            }
          }
        }
      }
    }
  },
  {
   //get rid of indexes and wrapper brackets
    "operation": "shift",
    "spec": {
      "*": {
        "*": ""
      }
    }
  }
]

the demo on the site http://jolt-demo.appspot.com/

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM