Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

How to extract specific node in JSON Databank

Parasofttoudaya
Parasofttoudaya Posts: 232 ✭✭

Hi Team,

I have a requirement where i have to get the specific node in json object.

from the below example, How do i fetch the "Node_12345", any help would be appreciatable.

"Node_12345": {
"Key": "XXXXX",
"value": "YYYYY"
},

I have use xpath : root\node() --> this gives me complete xml. But i need to fetch this node alone.

Comments

  • OmarR
    OmarR Posts: 233 admin

    Hey Uday,

    Do you want to capture the name of the node or the entire element? Try the following:

    Xpath: /root
    result: {"Node_12345":{"Key":"XXXXX","value":"YYYYY"}}

    Xpath: /root/Node_12345[1]/name()
    result: Node_12345

  • Parasofttoudaya
    Parasofttoudaya Posts: 232 ✭✭
    edited October 2017

    Hi Omar,

    Problem here is i dont have the node value.

    without the node values, is it possible to get all the nodes present in that loop..
    configs{
    "Node_1": {
    "Key": "XXXXX",
    "value": "YYYYY"
    },
    "Node_2": {
    "Key": "XXXXX",
    "value": "YYYYY"
    },
    "Node_3": {
    "Key": "XXXXX",
    "value": "YYYYY"
    },
    "Node_4": {
    "Key": "XXXXX",
    "value": "YYYYY"
    }
    }

    expected result is like

    Node_1
    Node_2
    Node_3
    Node_4

  • OmarR
    OmarR Posts: 233 admin

    Do they all have a partially similar name?
    If so, You may be able to use the "contains" function to retrieve all the node names that contain the shared word in their name.

  • Parasofttoudaya
    Parasofttoudaya Posts: 232 ✭✭
    edited October 2017

    They have all different names..

    Basically it supposed to be retrieved database, there are 1000 number of response like that and we wanted to make only one call... When we make one call its difficult to use the writable data source

  • Parasofttoudaya
    Parasofttoudaya Posts: 232 ✭✭

    Currently we can ignore of this question, I found another solution to loop thru the values.
    Passed the DB call output to writable data source and used regular xpath expression to retrieve the values.

    Thanks
    Udaya