0

I got a json like:

    {
   "message":{
      "2.21.59.0.4":{
         "eventData":{
            "optionalParameters":{
               "sysconRead":"1129:3,286:0,287:0,4072:1,915:14",
               "data_2222":"https://company.com/executions/35314/35314314/jcat/testlogs/10.136.75.13/201105_135857/10.136.75.13_filedump.zip",
               "sysconRead":"RP100:2000,RP145:16,RP146:2,RP147:4,RP15:100,RP150:813,RP45:500,RP74:9171,RP750:1,RP807:15",
               "data_3333":"https://company.com/executions/35314/35314314/jcat/testlogs/10.136.75.14/201105_135855/10.136.75.14_filedump.zip"
            }
         }
      }
   }
}

In the optionalParameters there are keys like data_2222 that has random numbers after data_. I am trying to write an Xpath expression that takes all the key-value pairs that match data_ but fail to create one. If I take e.g. $.message.*.eventData.optionalParameters. it returns all key-values like:

[
  {
    "sysconRead": "RP100:2000,RP145:16,RP146:2,RP147:4,RP15:100,RP150:813,RP45:500,RP74:9171,RP750:1,RP807:15",
    "data_2222": "https://company.com/executions/35314/35314314/jcat/testlogs/10.136.75.13/201105_135857/10.136.75.13_filedump.zip",
    "data_3333": "https://company.com/executions/35314/35314314/jcat/testlogs/10.136.75.14/201105_135855/10.136.75.14_filedump.zip"
  }
]

I just want it to return :

[
  {
   "data_2222": "https://company.com/executions/35314/35314314/jcat/testlogs/10.136.75.13/201105_135857/10.136.75.13_filedump.zip",
    "data_3333": "https://company.com/executions/35314/35314314/jcat/testlogs/10.136.75.14/201105_135855/10.136.75.14_filedump.zip"
  }
]
1
  • I think $.message.*.eventData.optionalParameters. is probably JsonPath. It certainly isn't XPath. The XPath equivalent would be ?message?*?eventData?optionalParameters Commented Nov 5, 2020 at 15:24

1 Answer 1

1

An XPath 3.1 expression to return the result you are looking for would be

[map:merge(?message?*?eventData?optionalParameters => 
   map:for-each(
     function($k,$v){if (matches($k, '^data_') then map{$k : $v} else ()}
   ))]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.