Extract Value by defined Name Value in JSON

Hello Community,

once again I’m asking for help… :wink:
I need to extract data of a JSON, with JSON Path and sometimes an Ungroup it worked pretty well, but now I’m on a bit tricky thing.

  "attribute" : [ {
    "name" : "CONTACT/URL",
    "values" : [ "http://www.urltohomepage.com" ]
  }, {
    "name" : "Value_of_AttrName2",
    "values" : [ "Ja" ]
  }, {
    "name" : "Value_of_AttrName3",
    "values" : [ "264" ]
  }, {
    "name" : "Value_of_AttrName4",
    "values" : [ "Nein" ]
  }, {
    "name" : "Valueof_AttrName5",
    "values" : [ "400" ]

For Example: I need the URL. But it can appear on position 0 like above, but also on position 5 or 3.
How is it possible to find the URL an extract the Link to the website?

Thanks and BR,
Sven

Hi @sven-abx ,
I’m assuming that the name of the attribute will always be “CONTACT/URL”.
If that is the case, I can think of two ways.

First would be to pull all the names and values from the attributes and then ungroup them, and finally use row-filter to find the one where name=“CONTACT/URL”

But the second would be to manually edit the json path to return the following:

$.attribute[?(@.name == "CONTACT/URL")].values[0]

As you can see from this link to my ChatGPT question

… I cheated :wink:

Note that the structure of your json may be slightly different to the sample, as I had to modify it to create a complete piece of json, but hopefully this will give sufficient pointers.

Find specific attribute within json collection.knwf (16.0 KB)

3 Likes

hey @takbb,

i don’t care if you cheated. :wink:
but now i should create a chat-gpt account. :smiley:

thank you,
sven

Hi @sven-abx , glad it worked for you and yes, most definitely create a free account. I use chatGPT most days now to speed up writing of snippets of Java, Python, regex, powershell… It’s not always exactly right first time but I interact with it the way I’d interact with a knowledgeable ( junior :wink:) developer to gradually refine what I need.

(and thanks for marking the solution :slightly_smiling_face:)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.