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

Trim values after forward flash

Source JSON:

{
  "accounts": [
    {
      "name": "accounts/189134493",
      "createTime": "2021-02-08T08:55:53.722Z",
      "updateTime": "2021-02-08T08:55:53.722Z"
    },
    {
      "name": "accounts/192303354",
      "createTime": "2021-03-16T14:22:04.865Z",
      "updateTime": "2021-03-16T14:22:04.865Z"
    }
  ],
  "nextPageToken": "APDpoXMhpjzh_oJqiqip6upnMH"
}

Expected:

[
  {
    "id": "1891344",
    "createTime": "2021-02-08T08:55:53.722Z",
    "updateTime": "2021-02-08T08:55:53.722Z"
  },
  {
    "id": "1923033",
    "createTime": "2021-03-16T14:22:04.865Z",
    "updateTime": "2021-03-16T14:22:04.865Z"
  }
]

I was only able to unnest values from accounts array with simple shift operation:

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

"spec": {
  "*": {
    "*": {
      "*": "[&1].&"
    }
  }
}

Now I need to grab values from name, and get value after accounts/ and store it as id.

>Solution :

You can successively use split and join functions within a modify transformation such as

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "accounts": {
        "*": {
          "name_": "=split('accounts/',@(1,name))", // split the pieces by the provided literal "accounts/"
          "id": "=join('',@(1,name_))" // combine the components of the newly formed arrays to yield string type values
        }
      }
    }
  },
  {
    "operation": "remove",
    "spec": {
      "accounts": {
        "*": {
          "nam*": ""
        }
      },
      "nextPageToken": ""
    }
  }
]

the demo on the site http://jolt-demo.appspot.com/ 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