Create a json string in webmethods

What product/components do you use and which version/fix level are you on? I am using webMethods 10.7

Is your question related to the free trial, or to a production (customer) instance? No

What are you trying to achieve? Please describe it in detail.

I am building a package that will bring data in, map it to a webMethods document which mirrors what the output json string should look like. Inside the document there are document lists defined. For all of the time, the input coming in will only have one ‘set’ of data, which is changing the document list to a document. I’m looking for a way to have the document lists stay as document lists even though there’s just one ‘set’ of data in them.

The input gets mapped to a webMethods document that looks like this:

transaction (defined as document)
transactionCode (defined as string)
party (defined as document)
person (defined as document
DOB (defined as String)
firstName (defined as String)
lastName (defined as String)
testArray (defined as a Document List)
item1 (defined as a String)
item2 (defined as a String)
testArray2 (defined as Docuemnt List)
code (defined as String)

After the document has been populated, it then gets translated to a json string using pub.json:documentToJSONString
The output json string is in this format:
{ “transaction” :
{ “transactionCode”: “NAME_DOB_SSN”
},
“party”:{
“person”:{
“birthDate”:“1900-01-01”
},
“firstName”:“John”,
“lastName”:“Smith”,
“partyIdentities”: [ {
“typeCode”: “SSN”,
“typeId”: “111222333”
}], “partyRoles”: [{
“roleCode”:“test”
}]
},
“lineOfBusinesses”: [{
“lineOfBusinessCode”:“test1”
},{
“lineOfBusinessCode”:“test2”
}]
}

Do you get any error messages? Please provide a full error message screenshot and log file. No.

Have you installed all the latest fixes for the products and systems you are using? Yes.

I am unable to replicate your issue, I have a json string that looks like

{ 
  "id":"12345",
  "values":[ {
       "a":"1",
       "b":"1"
    } ]
}

I converted it to a document and then back to a string and everything was fine, even though there is only one element in the value list.

Can you simplify your structure and outline the code steps that you have ?
regards,
John.

In your example:
{
“id”:“12345”,
“values”:[ {
“a”:“1”,
“b”:“1”
} ]
}
it stays true as an array as there are 2 occurances of data in it.

In my example
I need to end up with partyIdentities as an array with 1 occurance of SSN information which encompasses typeCode and typeId:

“partyIdentities”: [ {
“typeCode”: “SSN”,
“typeId”: “111222333”
}],

but I’m getting the result of partyIdentities as an Object with only one occurance of SSN info, even through I defined partyIdentities as a Document List in my flow:
“partyIdentities”: {
“typeCode”: “SSN”,
“typeId”: “111222333”
},

I’m loading input data into a webMethods document that looks like this:
image
then I’m doing
pub.json:documentToJSONString to create the JSON string the API I’m calling needs.

Can you share more detail about these steps? The symptom you’re describing sounds very much like what happens when parsing XML without a defined doc type, or arrays input in the xmlNodeToDocument call, that identifies what should be arrays.

Mine has only 1 element just like yours. I took your data and tried it with jsonStringToDocument and it worked perfectly.
How did you generate the document type ?
Did you create it manually or programatically ?
Are you referencing a document type in the input ‘jsonDocumentTypeName’ to jsonStringToDocument ?

I would recommend that you do not specify a document type as input to the jsonStringToDocument service.

regards,
John.

How is the input data loading into a webMethods document? Is the input converted using jsonStringToDocument service?

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