cancel
Showing results for 
Search instead for 
Did you mean: 

Get XML element in JSON array using XML o JSON converter

Hi Experts,

I need to get an array of JSON format, but unable to achieve it using XML to JSON converter. Current output:

{"accounts":{"resourceId":"No reply","currency":"SEK","product":"Product","name":"Name","clearingNumber":"CLNum","bban":"Bban","_links":{"balances":"","transactions":""}}}

expected output:

{"accounts":[{"resourceId":"Test","currency":"000","product":"Medlemskonto","name":"000000","clearingNumber":"0000","bban":"00000","_links":{"balances":{"href":"v1/accounts/000000000/balances"},"transactions":{"href":"v1/accounts/000000/transactions"}}}]}
Can this be achieved using streaming option, on element node but I am getting the array as the table cannot be empty.

Accepted Solutions (0)

Answers (2)

Answers (2)

0 Kudos

Hi ALl,

I was able to solve the issue. Thanks.

engswee
Active Contributor
0 Kudos

Hi Vaishali

If your XML payload has only 1 occurrence of accounts, then the standard XML-to-JSON converter will not automatically generate a JSON array for it. It only does so when the occurrence on the XML is more than 1.

If you need to "force" the accounts field to be a JSON array even when there is only 1 element inside it, then you need to use a custom XML-to-JSON conversion. You can try out using XML2JSONConverter in FormatConversionBean for CPI. Parameter arrayFieldList as detailed in this blog post provides you the option to "force" the field to be generated as a JSON array.

Regards

Eng Swee

0 Kudos

Hi Eng Swee,

The occurrence of accounts is set to 1is to many. Please see below screen shot:

accounts-occurence.png

Settings I am trying to do in standard converter:xmltojsonconverter-setting.png but the error is :Table may not contain empty rows.

Is there something wrong that I am trying to achieve.

Best Regards,

Vaishali

engswee
Active Contributor
0 Kudos

Hi vaishali.applicon

I wasn't aware that the standard converter allows custom array conversion when using the Streaming feature (have never used that).

I tried it out and it seems to work fine. Can you try this few things just to find out if your error could be due to other issues:-

- Uncheck "Suppress JSON Root Element

- Ensure your namespace setup is correct in both the converter, and also the overall IFlow (under Runtime Configuration)

If it still does not work, please provide your XSD schema and the sample source payload.

Regards

Eng Swee