Neuron ESB User Network

The Service Bus for the Connected Business

Hi guys,
I am working on a set of services where I need to convert from xml to json format.
I have been using the built-in JSON step as I prefer using the builtin steps rather than custom c# code .

The interface exposed by the service and agreed with the consumer have an object array in the output. The step by default convert the incoming xml into a json array if the corresponding xml node has more than one element, but if there is only one element than it result in a json object.

For Example

<contractLines>
<lineId>35639d01-cb69-4d0d-8747-164e33a15aec</lineId>
</contractLines>
<contractLines>
<lineId>1734312f-24df-48b6-8de6-4fed70560efa</lineId>
</contractLines>

==> JSON 


"contractLines": [
{
"lineId": "35639d01-cb69-4d0d-8747-164e33a15aec",
},
{
"lineId": "1734312f-24df-48b6-8de6-4fed70560efa",
}
]

But when only one line is available it generates a simple Json object...

<contractLines>
<lineId>35639d01-cb69-4d0d-8747-164e33a15aec</lineId>
</contractLines>

==> JSON 


"contractLines": 
{
"lineId": "35639d01-cb69-4d0d-8747-164e33a15aec",
}

I saw on the Newtonsoft documentation that is possible to override this behavior using a special tag,

<contractLines json:Array="true" xmlns:json="http://james.newtonking.com/projects/json">

and in this way it always generate an array.

The builtin step does not seem to implement this feature, but it might be an improvement in order to avoid writing custom code ...

What do you think?

Is it feasible to add it?

Thank you

F. 

Tags: json

Views: 449

Reply to This

Replies to This Discussion

can you send me the link to the newtonsoft documentation that describes this?

Fabrizio,

This works the way you want it to.  I just used this XML with the JSON step:

<contractLines json:Array="true" xmlns:json="http://james.newtonking.com/projects/json">
   <lineId>35639d01-cb69-4d0d-8747-164e33a15aec</lineId>
</contractLines>

And this is the JSON output:

{
"contractLines": [{
"lineId": "35639d01-cb69-4d0d-8747-164e33a15aec"
}]
}

Notice that lineId has been put into an array.  Are you expecting a different output?

Joe

@Martin, this is the link to the documentation
http://www.newtonsoft.com/json/help/html/ConvertXmlToJsonForceArray...

@Joe, yes, you're right. It works but I had set the option Remove Xml Namespace = true and this probably removes the newtonsoft namespace before the conversion, resulting in the following json

{"item":

 {"@Array":"true",

     "itemNumber":"6696903"

 }

}

ok....I think I have a modification in that will make this work. I'll send you a build today to test

build is taking a bit longer...found another weird bug.  

RSS

Neuron ESB Product Support Forums and Communities

Latest Activity

Anupama Nair posted a discussion

Marketo Adapter Invalid Token

Hi,We are using the Marketo adapter to push account updates to Marketo. It works well for some time then starts failing with Invalid Token unless restarted. Is there a configuration that can be done so it can auto refresh the token when required?Thanks!See More
Nov 6, 2023
Sayantini Basak posted a discussion

Maximum payload size(REST API) for requests interfacing to NeuronESB

I am new to Neuron ESB and in our current scenario,We need to process batch transactions comprising of ~1000 records and send them to Neuron ESB for further processing. I would like to understand what is the maximum size of payload that can be transferred using REST interface to Neuron ESB.See More
Jul 22, 2022
Profile IconRobert E Dunie and Sayantini Basak joined Neuron ESB User Network
Apr 28, 2022
Profile IconDayanand, Frederic C, Steffen Greve-Oksfeldt and 1 more joined Neuron ESB User Network
Mar 16, 2022
Profile IconCam Vong and Mitja Luznar joined Neuron ESB User Network
Jan 27, 2022
Profile IconWill Hitzges, Chad Parsons, michael larsen and 4 more joined Neuron ESB User Network
Jun 11, 2021
Anupama Nair posted a discussion

ODBC stored proc polling with temporary tables

We have set up an ODBC adapter to poll a stored proc.We found that if the stored proc has a temporary table defined the rows returned are always 0.Any idea why this would be and what we can do to get around it?See More
Dec 14, 2020
Prasanth Kharade is now a member of Neuron ESB User Network
Dec 30, 2019

Badge

Loading…

© 2024   Created by Neuron Admin.   Powered by

Badges  |  Report an Issue  |  Terms of Service