ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » JSON array using graphical mapping node

Post new topic  Reply to topic
 JSON array using graphical mapping node « View previous topic :: View next topic » 
Author Message
mrkumar
PostPosted: Sat Jul 02, 2016 8:58 am    Post subject: JSON array using graphical mapping node Reply with quote

Novice

Joined: 02 Jul 2016
Posts: 18

The JSON array object is coming as repeatables when we convert an xml to JSON using graphical mapping node in IIB v 10.0.0.4

for example

{
"sample":{"red"},
"sample":{"blue"},
"sample":{"green"}
}

This is an invalid JSON
desired output is

{
"sample":["red","blue","green"]
}


I am facing this issue while converting a soap response to JSON. So there are so many arrays like this. a prodcut like IIB for sure should have a aumatic converstion of arrays right ?

please correct me if I am wrong or if there is any other way to do it so that i can send the JSON arrays as a response.

I really appreciate your help !
_________________
If you fail, call it as Version1.0
Back to top
View user's profile Send private message
smdavies99
PostPosted: Sat Jul 02, 2016 9:52 am    Post subject: Reply with quote

Jedi Council

Joined: 10 Feb 2003
Posts: 6076
Location: Somewhere over the Rainbow this side of Never-never land.

Have you looked for similar posts here on this topic.
I can remember JSON arrays being discussed before.
_________________
WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995

Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions.
Back to top
View user's profile Send private message
mrkumar
PostPosted: Sat Jul 02, 2016 10:51 am    Post subject: Reply with quote

Novice

Joined: 02 Jul 2016
Posts: 18

smdavies99 wrote:
Have you looked for similar posts here on this topic.
I can remember JSON arrays being discussed before.



I did search for this and find some post for about manual manipulation of individual json array objects. however I want to do know how i can do via graphical mapping node which does things dynamic. Since my web service returns more than one JSON array objects and has many several service operations such as
_________________
If you fail, call it as Version1.0
Back to top
View user's profile Send private message
timber
PostPosted: Sun Jul 03, 2016 12:43 pm    Post subject: Reply with quote

Grand Master

Joined: 25 Aug 2015
Posts: 1280

I've posted code that will convert repeating elements into JSON arrays - I believe it's somewhere on the forum in a related post.

Quote:
a prodcut like IIB for sure should have a automatic conversion of arrays right
You seem to think this is a simple problem. It is actually a rather tricky problem to solve if you want it to work accurately. You need to work out whether each non-repeating tag is
a) a single tag that is not meant to be an array ( xsd maxOccurs=1 )
or
b) an array with exactly one member ( minOccurs=1, maxOccurs>1 )
That can only be done if the XML is validated against an XSD. You have to use the PSVI information provided by the XML parser. That's not trivial at all. Does that answer your question?
Back to top
View user's profile Send private message
mrkumar
PostPosted: Sun Jul 03, 2016 7:06 pm    Post subject: Reply with quote

Novice

Joined: 02 Jul 2016
Posts: 18

timber wrote:
I've posted code that will convert repeating elements into JSON arrays - I believe it's somewhere on the forum in a related post.

Quote:
a prodcut like IIB for sure should have a automatic conversion of arrays right
You seem to think this is a simple problem. It is actually a rather tricky problem to solve if you want it to work accurately. You need to work out whether each non-repeating tag is
a) a single tag that is not meant to be an array ( xsd maxOccurs=1 )
or
b) an array with exactly one member ( minOccurs=1, maxOccurs>1 )
That can only be done if the XML is validated against an XSD. You have to use the PSVI information provided by the XML parser. That's not trivial at all. Does that answer your question?



you are right. I dont want to restrict the multiple occurances of an object. I want to group them in an array for a JSON format. since we cant have same object name repeated in JSON.
_________________
If you fail, call it as Version1.0
Back to top
View user's profile Send private message
mrkumar
PostPosted: Tue Jul 05, 2016 3:15 pm    Post subject: Reply with quote

Novice

Joined: 02 Jul 2016
Posts: 18

mrkumar wrote:
timber wrote:
I've posted code that will convert repeating elements into JSON arrays - I believe it's somewhere on the forum in a related post.

Quote:
a prodcut like IIB for sure should have a automatic conversion of arrays right
You seem to think this is a simple problem. It is actually a rather tricky problem to solve if you want it to work accurately. You need to work out whether each non-repeating tag is
a) a single tag that is not meant to be an array ( xsd maxOccurs=1 )
or
b) an array with exactly one member ( minOccurs=1, maxOccurs>1 )
That can only be done if the XML is validated against an XSD. You have to use the PSVI information provided by the XML parser. That's not trivial at all. Does that answer your question?



you are right. I dont want to restrict the multiple occurances of an object. I want to group them in an array for a JSON format. since we cant have same object name repeated in JSON.



is this a bug in the JSON parser to not have repeated JSON elements in a JSON array object ?
_________________
If you fail, call it as Version1.0
Back to top
View user's profile Send private message
timber
PostPosted: Tue Jul 05, 2016 11:49 pm    Post subject: Reply with quote

Grand Master

Joined: 25 Aug 2015
Posts: 1280

Quote:
is this a bug in the JSON parser to not have repeated JSON elements in a JSON array object ?
No. This is not a bug. Please review what I said once again.

The JSON parser does not *assume* that two consecutive elements with the same name are *definitely* an array. They might be two occurrences of a non-array element. Having said that, a JSON object should not have two keys with the same name so you could argue that the IIB JSON parser should offer this behaviour as an option.

However...you still have the situation where the input XML contains exactly one occurrence of the tag <myArray> because it just happened to have only one occurrence. What do you want the JSON parser to do about that? Output a JSON field when there is 1 occurrence, and a JSON array when there are 2+ occurrences?
Back to top
View user's profile Send private message
mrkumar
PostPosted: Wed Jul 06, 2016 10:48 am    Post subject: Reply with quote

Novice

Joined: 02 Jul 2016
Posts: 18

timber wrote:
Quote:
is this a bug in the JSON parser to not have repeated JSON elements in a JSON array object ?
No. This is not a bug. Please review what I said once again.

The JSON parser does not *assume* that two consecutive elements with the same name are *definitely* an array. They might be two occurrences of a non-array element. Having said that, a JSON object should not have two keys with the same name so you could argue that the IIB JSON parser should offer this behaviour as an option.

However...you still have the situation where the input XML contains exactly one occurrence of the tag <myArray> because it just happened to have only one occurrence. What do you want the JSON parser to do about that? Output a JSON field when there is 1 occurrence, and a JSON array when there are 2+ occurrences?



ok valid point. that it doesnt know the difference between an array element coming once with that a non array element that comes only once.

but we have to do something for the elements that come as 2+ occurrences right ? since its not a valid JSON anymore.

that we cant have the repeating elements in JSON. because i am getting JSON parser error in browser for that call. it says duplicate element identified.

I am seeing parser error in the browser with duplicate JSON element that occurs more than once.

so as of now, I am creating mapping node to put them in a JSON array and then giving it as response to browser.

hence I am trying to find a generic solution to my 15+ operations in the service.
_________________
If you fail, call it as Version1.0
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » JSON array using graphical mapping node
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.