0

need to transform based on the element value input.json

{
  "Result": {
    "owner": {
      "name": "test  user"
    },
    "Components": [
      {
        "id": "123-456-789"
      }
    ],
    "123-456-789": {
      "temp": {
        "emip": "abc",
        "teto": "123"
      }
    }
  }
}

transform json

[
  {
    "operation": "shift",
    "spec": {
      "Result": {
        "Components": {
          "*": {
            "id": "compId"
          }
        },
        "compId": {
          "@": "component"
        }
      }
    }
  },
  {
    "operation": "default",
    "spec": {
      "compId": null
    }
  }
]

output expected to be

 "123-456-789": {
      "temp": {
        "emip": "abc",
        "teto": "123"
      }
    }

but the result answer is below , when I hard code the value with 123-456-789 then I get the value but I need to take the value dynamically.

{
  "compId" : "123-456-789"
}

1 Answers1

0

Spec

[
  {
    "operation": "shift",
    "spec": {
      "Result": {
        "Components": {
          "*": { // components array index
            "id": {
              "*": { // match any value of id
                // go back up the tree 5 levels, and then 
                //  lookup a key based on the value of the "id"
                //  and write that to the output at at that same 
                //  key
                "@(4,&)": "&1"
              }
            }
          }
        }
      }
    }
  }
]
Milo S
  • 4,466
  • 1
  • 19
  • 22