Forum Discussion

TRACEYSMARTBEAR's avatar
TRACEYSMARTBEAR
New Member
2 years ago

How to wrap json code so i pass in a variable as the body contents to a webservice

I am using SOAPUI and testing webservices.
Media/Type application/json
Having the below as follows works the webservices is called.
Example below - commented out names etc for here

document":{
"id":"WEBSERVICENAME",
"tranType":"INSERT",
"rows":[
{
"row":{
"rsId":"WEBSERVICENAME_MYFIELD",
"data":{

},
"children":[


{
"row":{
"rsId":"WEBSERVICESNAME_ADDTOCUSTOMER",
"tranType":"INSERT",
"data":{
"MYNAME":"Somevalue",

}
}
]
}
}

 

How do i wrap this in a variable 
I tried this

var s = '

document":{
"id":"WEBSERVICENAME",
"tranType":"INSERT",
"rows":[
{
"row":{
"rsId":"WEBSERVICENAME_MYFIELD",
"data":{

},
"children":[


{
"row":{
"rsId":"WEBSERVICESNAME_ADDTOCUSTOMER",
"tranType":"INSERT",
"data":{
"MYNAME":"Somevalue",

}
}
]
}
}
';

var obj = JSON.parse(s);


Just get message invalid structure returned utils.jsutils.json.JSONParserTokenManager.getNextToken(JSONParserTokenManager.java:547

  • TNeuschwanger's avatar
    TNeuschwanger
    Champion Level 1

    Hello TRACEYSMARTBEAR 

     

    Try putting your content between 3 double quotes...  """  i.e. :

    def String jsonStr = """
    {
      "step_list": [
        {
          "end_date": "2035-09-01T00:00:00",
          "payments": 12,
          "sequence": 1
        },
        {
          "end_date": "2035-09-01T00:00:00",
          "payments": 67,
          "sequence": 2
        }
      ]
    }
    """;

     

     

    • farrahkohn's avatar
      farrahkohn
      Occasional Visitor

      TNeuschwanger wrote:

      Hello TRACEYSMARTBEAR 

       

      Try putting your content between 3 double quotes...  """  i.e. :

       

      def String jsonStr = """
      {
        "step_list": [
          {
            "end_date": "2035-09-01T00:00:00",
            "payments": 12,
            "sequence": 1
          },
          {
            "end_date": "2035-09-01T00:00:00",
            "payments": 67,
            "sequence": 2
          }
        ]
      }
      """;

       


      Will try later, thanks.