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 convert databank text string to JSONObject?

Parasofttoudaya
Parasofttoudaya Posts: 232 ✭✭
edited September 2017 in SOAtest

I am extracting a json response to dataBank variable and assigning to extension tool.
On top of the extension tool adding json databank.
Getting error as invalid json.

is there any option like Transformer for json, like we have XMLTransformer for XML?

Tagged:

Comments

  • jakubiak
    jakubiak Posts: 795 admin

    Have you validated that what you are passing to the JSON Data Bank is formatted as valid JSON?

  • trivedispt
    trivedispt Posts: 2
    edited December 2018

    Hello..

    In JSON Data Bank "myDataBank" I have created a Data Source column named "persons" that has value in the format
    {
    "person" : [
    {
    "firstName" : "ABC",
    "lastName" : "XYZ"
    }
    ]
    }

    When I extract the Datasource column "persons" using

    var personList = context.getValue("myDataBank", "persons");

    personList is a string not an object or an array. How to convert string to JSON or is there any way to access the string data in personList.

    Something like personList[0].firstName

  • jakubiak
    jakubiak Posts: 795 admin

    One option is to change your data bank to extract the string directly (like "firstName") instead of "person". Or, if you are using scripting, you could use JavaScript (Oracle Nashorn) as your scripting language and use JSON.parse() to turn the string into a JSON object that you can use.

  • trivedispt
    trivedispt Posts: 2

    I changed to JavaScript (Oracle Nashorn). It worked. Thank you.