Author |
Message
|
mrkumar |
Posted: Sat Jul 02, 2016 8:47 am Post subject: Regarding namepsace in JSON |
|
|
 Novice
Joined: 02 Jul 2016 Posts: 18
|
I am fairly new to IIB. I would appreciate any help on my issue that I am facing.
I am using IIB v 10.0.0.4 to call a soap service and convert the xml to JSON. Since the resposnse XML has namepsace. The JSON format is getting parser error in browser.
I know if I set the name space to null, it removes it. however it is in multiple places.
is there any easy way to iterate it and remove xmlns attribute of JSON ?
I would rather like to find if there is a option to skip NAMEPSPACE either in esql or via graphical mapping node.
Please advice. I really appreciat eit.
Thanks for help. I have pasted the response that I received
{
"getInboxReportsResponse": {
"ReportNs": "http://www.sample.com/01/14/2010/V1.0/Report",
"ns1": "http://www.sample.com/01/14/2010/V1.0/Result",
"ns2": "http://www.sample.com/02/10/2010/V1.0/ncp/messages/resultsMessage/",
"ns3": "http://www.sample.com/03/12/2010/V1.0/ncp/results/reportManagement/",
"tns": "http://www.sample.com/03/08/2010/V1.0/ncp/results/reportSearch/",
"rpt": "http://www.sample.com/03/12/2010/V1.0/ncp/types/reportManagement/",
"ns4": "http://www.sample.com/03/08/2010/V1.0/ncp/types/reportSearch/",
"del": "http://www.sample.com/02/10/2010/V1.0/ncp/types/resultsDelivery/",
"rbe": "http://www.sample.com/02/10/2010/V1.0/ncp/types/BusinessError/",
"totalNumberFound": 1050,
"sample1": {
"xmlns": "http://www.sample.com/01/14/2010/V1.0/Result",
"sample2": {
"xmlns": "http://www.sample.com/02/10/2010/V1.0/ncp/messages/resultsMessage/",
"sample3": {
"total": 2
}
}
}
}
}
where as I wanted something like with no urls and xmlns which is coming from namespace that are in xsd of the web service that I called to get a response in IIB
{
"getInboxReportsResponse": {
"totalNumberFound": 1050,
"sample1": {
"sample2": {
"sample3": {
"total": 2
}
}
}
}
}
Last edited by mrkumar on Mon Jul 04, 2016 1:12 pm; edited 1 time in total |
|
Back to top |
|
 |
timber |
Posted: Sun Jul 03, 2016 12:47 pm Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
Quote: |
Since the resposnse XML has namepsace. The JSON format is getting parser error in browser. |
Not sure that I understand. Please can you explain that again. I cannot work out whether you are having a problem with a 'namespace' or an xmlns attribute.
It's probably a good idea to post the response ( remove anything confidential first ). If you do, please the [c o d e] button (above the edit window) to make the JSON readable. |
|
Back to top |
|
 |
mrkumar |
Posted: Sun Jul 03, 2016 3:42 pm Post subject: |
|
|
 Novice
Joined: 02 Jul 2016 Posts: 18
|
timber wrote: |
Quote: |
Since the resposnse XML has namepsace. The JSON format is getting parser error in browser. |
Not sure that I understand. Please can you explain that again. I cannot work out whether you are having a problem with a 'namespace' or an xmlns attribute.
It's probably a good idea to post the response ( remove anything confidential first ). If you do, please the [c o d e] button (above the edit window) to make the JSON readable. |
I meant the name space. When we have a namespace in xsd, it comes int he response xml, so when you convert that to JSON. it comes as xmlns attribute in JSON.
so trying to figure an better solution to get ride of them in my final json output rather than changing each response JSON. _________________ If you fail, call it as Version1.0  |
|
Back to top |
|
 |
smdavies99 |
Posted: Sun Jul 03, 2016 9:27 pm Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
mrkumar wrote: |
I meant the name space. When we have a namespace in xsd, it comes int he response xml, so when you convert that to JSON. it comes as xmlns attribute in JSON.
|
Why not show us what you mean. Examples of before and after (with names etc obfuscates please) say a lot on explanation and possible missunderstandings. _________________ 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 |
|
 |
mrkumar |
Posted: Mon Jul 04, 2016 1:10 pm Post subject: |
|
|
 Novice
Joined: 02 Jul 2016 Posts: 18
|
smdavies99 wrote: |
mrkumar wrote: |
I meant the name space. When we have a namespace in xsd, it comes int he response xml, so when you convert that to JSON. it comes as xmlns attribute in JSON.
|
Why not show us what you mean. Examples of before and after (with names etc obfuscates please) say a lot on explanation and possible missunderstandings. |
Thanks for help. I have pasted the response that I received
{
"getInboxReportsResponse": {
"ReportNs": "http://www.sample.com/01/14/2010/V1.0/Report",
"ns1": "http://www.sample.com/01/14/2010/V1.0/Result",
"ns2": "http://www.sample.com/02/10/2010/V1.0/ncp/messages/resultsMessage/",
"ns3": "http://www.sample.com/03/12/2010/V1.0/ncp/results/reportManagement/",
"tns": "http://www.sample.com/03/08/2010/V1.0/ncp/results/reportSearch/",
"rpt": "http://www.sample.com/03/12/2010/V1.0/ncp/types/reportManagement/",
"ns4": "http://www.sample.com/03/08/2010/V1.0/ncp/types/reportSearch/",
"del": "http://www.sample.com/02/10/2010/V1.0/ncp/types/resultsDelivery/",
"rbe": "http://www.sample.com/02/10/2010/V1.0/ncp/types/BusinessError/",
"totalNumberFound": 1050,
"sample1": {
"xmlns": "http://www.sample.com/01/14/2010/V1.0/Result",
"sample2": {
"xmlns": "http://www.sample.com/02/10/2010/V1.0/ncp/messages/resultsMessage/",
"sample3": {
"total": 2
}
}
}
}
}
where as I wanted something like with no urls and xmlns which is coming from namespace that are in xsd of the web service that I called to get a response in IIB
{
"getInboxReportsResponse": {
"totalNumberFound": 1050,
"sample1": {
"sample2": {
"sample3": {
"total": 2
}
}
}
}
} _________________ If you fail, call it as Version1.0  |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Jul 04, 2016 7:16 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Your current schema is following the wsdl and has the namespaces. Create a different schema for your JSON without the namespaces and map one to the other. See how that works all out for you...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
mrkumar |
Posted: Mon Jul 04, 2016 10:51 pm Post subject: |
|
|
 Novice
Joined: 02 Jul 2016 Posts: 18
|
fjb_saper wrote: |
Your current schema is following the wsdl and has the namespaces. Create a different schema for your JSON without the namespaces and map one to the other. See how that works all out for you...  |
Thanks for your input
I loaded the xsd by creating a new message mode. should I change those xsd by creating schemas that dont have namespaces and then i should be good ?
or create a json objects with no namespace in mapping node and then map the JSON with namespace to that and get JSON without namespaces ? _________________ If you fail, call it as Version1.0  |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Jul 05, 2016 4:05 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
It appears you are simply copying an entire XML structure, including namespace declarations, into a JSON record.
So I don't think
Quote: |
"ReportNs": "http://www.sample.com/01/14/2010/V1.0/Report", |
is a JSON namespace. I think it's a JSON element with a name of 'ReportNS' and a value of "http://..."
So if you don't want to copy those elements, make sure your statements that create your output message don't copy XMLNSC.NamespaceDecl elements. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
joebuckeye |
Posted: Tue Jul 05, 2016 5:18 am Post subject: |
|
|
 Partisan
Joined: 24 Aug 2007 Posts: 365 Location: Columbus, OH
|
mqjeff wrote: |
It appears you are simply copying an entire XML structure, including namespace declarations, into a JSON record.
So I don't think
Quote: |
"ReportNs": "http://www.sample.com/01/14/2010/V1.0/Report", |
is a JSON namespace. I think it's a JSON element with a name of 'ReportNS' and a value of "http://..."
So if you don't want to copy those elements, make sure your statements that create your output message don't copy XMLNSC.NamespaceDecl elements. |
I think the OP is wanting broker to handle this automatically and we are seeing the limits to a generic XML to JSON transformation.
The coder would have to put into their code which attributes belong in the JSON output and which do not. If they are lucky the XSD isn't using any attributes so they could set up their code to ignore any attributes, if not then some method to determine which need to go into the output and which need to stay out will need to be developed. |
|
Back to top |
|
 |
mrkumar |
Posted: Tue Jul 05, 2016 8:31 am Post subject: |
|
|
 Novice
Joined: 02 Jul 2016 Posts: 18
|
joebuckeye wrote: |
mqjeff wrote: |
It appears you are simply copying an entire XML structure, including namespace declarations, into a JSON record.
So I don't think
Quote: |
"ReportNs": "http://www.sample.com/01/14/2010/V1.0/Report", |
is a JSON namespace. I think it's a JSON element with a name of 'ReportNS' and a value of "http://..."
So if you don't want to copy those elements, make sure your statements that create your output message don't copy XMLNSC.NamespaceDecl elements. |
I think the OP is wanting broker to handle this automatically and we are seeing the limits to a generic XML to JSON transformation.
The coder would have to put into their code which attributes belong in the JSON output and which do not. If they are lucky the XSD isn't using any attributes so they could set up their code to ignore any attributes, if not then some method to determine which need to go into the output and which need to stay out will need to be developed. |
joe. you are right, I want broker to handle this automatically. I thought there might be some settings that i can enable namespace or not in JSON (as name and value). But it seems like there is no option other than manually writing code to say what needs to go and what not.
Unfortunately manually writing becomes not that direct when we call A SOAP service that has more than 15 operations. I ended up writing more and more separate nodes for individual response.
Thanks all for your inputs. _________________ If you fail, call it as Version1.0  |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Jul 05, 2016 8:54 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You can write code that copies elements from XMLNSC to JSON and skips elements of type XMLNSC.NamespaceDecl without knowing what the name of the elements are. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
mrkumar |
Posted: Tue Jul 05, 2016 9:27 am Post subject: |
|
|
 Novice
Joined: 02 Jul 2016 Posts: 18
|
mqjeff wrote: |
You can write code that copies elements from XMLNSC to JSON and skips elements of type XMLNSC.NamespaceDecl without knowing what the name of the elements are. |
as of now , I am doing
SET OutputRoot.JSON.Data = InputRoot.XMLNSC;
since I dont know when and where type XMLNSC.NamespaceDecl comes in a response and then creating a JSON mapping node for every single response and mapping it.
is that something that i have to loop through every elements and see if there is a type XMLNSC.NamespaceDecl and remove it in esql ? _________________ If you fail, call it as Version1.0  |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Jul 05, 2016 9:29 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
mrkumar wrote: |
is that something that i have to loop through every elements and see if there is a type XMLNSC.NamespaceDecl and remove it in esql ? |
merely don't copy it. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
mrkumar |
Posted: Wed Jul 06, 2016 6:10 pm Post subject: |
|
|
 Novice
Joined: 02 Jul 2016 Posts: 18
|
mqjeff wrote: |
mrkumar wrote: |
is that something that i have to loop through every elements and see if there is a type XMLNSC.NamespaceDecl and remove it in esql ? |
merely don't copy it. |
thank you for the wise suggestion.
Do you know any iterating way of going thro the elements & child elements so that I can look for type XMLNSC.NamespaceDecl ? _________________ If you fail, call it as Version1.0  |
|
Back to top |
|
 |
mrkumar |
Posted: Wed Jul 06, 2016 6:11 pm Post subject: |
|
|
 Novice
Joined: 02 Jul 2016 Posts: 18
|
mrkumar wrote: |
mqjeff wrote: |
mrkumar wrote: |
is that something that i have to loop through every elements and see if there is a type XMLNSC.NamespaceDecl and remove it in esql ? |
merely don't copy it. |
thank you for the wise suggestion.
Do you know any iterating way of going thro the elements & child elements so that I can look for type XMLNSC.NamespaceDecl ? |
as of now i navigate thro the input.xmlnsc by specificying elements name and its children.
it would be nice to have a generic one to go thor so that I can use it for any kinds of response. _________________ If you fail, call it as Version1.0  |
|
Back to top |
|
 |
|