Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Who agreed with this solution

avatar
Expert Contributor

@dg 
Your desired output contains DG as value for userLabel. I am not sure if it is a typo, so, I tried converting it as well. If not needed, you can remove the modify-overwrite-beta part.

[
{
"operation": "modify-overwrite-beta",
"spec": {
"userLabel": "DG"
}
},
{
"operation": "shift",
"spec": {
"Types": {
"*": {
"subTypes": {
"*": {
"*": {
"$0": "Types[&4].subType[&2].Name",
"*": {
"$": "Types[&5].subType[&3].CounterNames[]",
"@": "Types[&5].subType[&3].CounterValues[]"
}
}
}
},
"*": "Types[&1].&"
}
},
"*": "&"
}
},
{
"operation": "shift",
"spec": {
"Types": {
"*": {
"subType": {
"*": {
"CounterNames": {
"*": "Types[&4].subType[&2].Counters[&].name"
},
"CounterValues": {
"*": "Types[&4].subType[&2].Counters[&].value"
},
"*": "Types[&3].subType[&1].&"
}
},
"*": "Types[&1].&"
}
},
"*": "&"
}
}
]

Here, the second spec(first shift) gives the following:

{
  "vendor" : "myINC",
  "beginTime" : "2020-01-21T10:00:00+08:00",
  "userLabel" : "DG",
  "Types" : [ {
    "Name" : "type001",
    "subType" : [ {
      "Name" : "subtype003",
      "CounterNames" : [ "counter1", "counter5", "counter54" ],
      "CounterValues" : [ "0", "0", "0" ]
    }, {
      "Name" : "subtype001",
      "CounterNames" : [ "counter002", "counter5", "counter65" ],
      "CounterValues" : [ "0", "0", "0" ]
    } ]
  }, {
    "Name" : "type002",
    "subType" : [ {
      "Name" : "subtype006",
      "CounterNames" : [ "counter1", "counter5", "counter54" ],
      "CounterValues" : [ "0", "0", "0" ]
    }, {
      "Name" : "subtype009",
      "CounterNames" : [ "counter002", "counter5", "counter65" ],
      "CounterValues" : [ "0", "0", "0" ]
    } ]
  } ]
}

The last spec gives you the desired output

View solution in original post

Who agreed with this solution