How to convert databank text string to JSONObject?

ParasofttoudayaParasofttoudaya Posts: 212 ✭✭
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

  • jakubiakjakubiak Posts: 424 admin

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

  • trivedispttrivedispt 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

  • jakubiakjakubiak Posts: 424 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.

  • trivedispttrivedispt Posts: 2

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

Sign In or Register to comment.