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 » How to add value/name in JSON

Post new topic  Reply to topic
 How to add value/name in JSON « View previous topic :: View next topic » 
Author Message
mr2kn
PostPosted: Fri Feb 12, 2016 12:05 pm    Post subject: How to add value/name in JSON Reply with quote

Apprentice

Joined: 26 Jan 2016
Posts: 46

Hi,
im working on IIB9 and creating 1st time in the JSON format like this

data={"start":0,"max":999}

and when I create it will output like this

{"data=":"","start":0,"max":999}

code:
CREATE LASTCHILD OF OutputRoot.JSON.Data TYPE NameValue NAME 'data=' VALUE '';
SET OutputRoot.JSON.Data.start = 0;
SET OutputRoot.JSON.Data.max = 999;

is the correct format ?
thank you in advance and appreciate
Back to top
View user's profile Send private message
maurito
PostPosted: Fri Feb 12, 2016 11:25 pm    Post subject: Re: How to add value/name in JSON Reply with quote

Partisan

Joined: 17 Apr 2014
Posts: 358

mr2kn wrote:
Hi,
im working on IIB9 and creating 1st time in the JSON format like this

data={"start":0,"max":999}

and when I create it will output like this

{"data=":"","start":0,"max":999}

code:
CREATE LASTCHILD OF OutputRoot.JSON.Data TYPE NameValue NAME 'data=' VALUE '';
SET OutputRoot.JSON.Data.start = 0;
SET OutputRoot.JSON.Data.max = 999;

is the correct format ?
thank you in advance and appreciate

Have you looked at the examples in the knowledge centre ?
Back to top
View user's profile Send private message
stoney
PostPosted: Sat Feb 13, 2016 4:27 am    Post subject: Re: How to add value/name in JSON Reply with quote

Centurion

Joined: 03 Apr 2013
Posts: 140

mr2kn wrote:
data={"start":0,"max":999}


This is not a valid JSON message, and you will not be able to produce a message like this in IIB using the JSON domain.
It is invalid because of the "data=" at the start of the message. Why do you need this part in your output message?
Back to top
View user's profile Send private message
mr2kn
PostPosted: Sun Feb 14, 2016 9:57 am    Post subject: Reply with quote

Apprentice

Joined: 26 Jan 2016
Posts: 46

agree that this invalid message and json message it should be {"start":0, "max":999} but my endpoint is accepting like this only else im receiving the error message
even I tried like this
SET outputroot.JSON.Data."data=".start =0;
SET outputroot.JSON.Data."data=".max = 999;

and output is like this {"data=":}{"start":0, "max":999}

and tried this also
SET outputroot.JSON.Data = 'data='
SET outputroot.JSON.Data.start =0;
SET outputroot.JSON.Data.max = 999;

output something like is{"data=":,"start":0,"max":999"}
Back to top
View user's profile Send private message
stoney
PostPosted: Sun Feb 14, 2016 10:10 am    Post subject: Reply with quote

Centurion

Joined: 03 Apr 2013
Posts: 140

Yes, I wouldn't expect that to work - you will not get the JSON domain to produce something with "data=" at the start.
Instead you'll have to use a combination of the JSON domain and the BLOB domain to prefix the "data=" onto the serialized JSON.
Something like:

Code:
CREATE LASTCHILD OF OutputLocalEnvironment.Variables DOMAIN('JSON');
SET OutputLocalEnvironment.Variables.JSON.Data.start = 0;
SET OutputLocalEnvironment.Variables.JSON.Data.max = 999;
DECLARE json BLOB ASBITSTREAM(OutputLocalEnvironment.Variables.JSON CCSID 1208);
DECLARE prefix BLOB CAST('data=' AS BLOB CCSID 1208);
SET OutputRoot.BLOB.BLOB = prefix || json;

-- or --

DECLARE json BLOB ASBITSTREAM(InputRoot.JSON CCSID 1208);
DECLARE prefix BLOB CAST('data=' AS BLOB CCSID 1208);
SET OutputRoot.BLOB.BLOB = prefix || json;
Back to top
View user's profile Send private message
timber
PostPosted: Mon Feb 15, 2016 2:18 am    Post subject: Reply with quote

Grand Master

Joined: 25 Aug 2015
Posts: 1292

Quote:
agree that this invalid message and json message it should be {"start":0, "max":999} but my endpoint is accepting like this only else im receiving the error message
Do the team who manage this endpoint know that they have a problem? I understand that you may not be able to communicate directly with them, but you should definitely flag this up.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Mon Feb 15, 2016 5:54 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Did the receiving team write their own JSON parser... ?
using an element name of "abc=", for any abc, is just weird. And likely bad practice.
_________________
chmod -R ugo-wx /
Back to top
View user's profile Send private message
mr2kn
PostPosted: Mon Feb 15, 2016 7:51 am    Post subject: Reply with quote

Apprentice

Joined: 26 Jan 2016
Posts: 46

Thank you very much, Stoney
the example you gave that worked,

The team knows this endpoint have the prefix in the json it and earlier in java also they have written with passing this value as string

and receiving team have their own json parser and details they have not shared how they are doing it

once again thank you all giving the guidance and discussion about this topic
Back to top
View user's profile Send private message
mgk
PostPosted: Mon Feb 15, 2016 1:14 pm    Post subject: Reply with quote

Padawan

Joined: 31 Jul 2003
Posts: 1642

Assuming you are sending this directly to an output node, there is a small optimization you can make here to save copying the bitstream by not concatenating it yourself:

Code:
DECLARE json BLOB ASBITSTREAM(InputRoot.JSON CCSID 1208);
DECLARE prefix BLOB CAST('data=' AS BLOB CCSID 1208);
SET OutputRoot.BLOB.BLOB[1] = prefix;
SET OutputRoot.BLOB.BLOB[2] = json;


With the code above, the output node will concatenate it for you instead...

Kind regards,
_________________
MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions.
Back to top
View user's profile Send private message
mr2kn
PostPosted: Tue Feb 16, 2016 6:46 am    Post subject: Reply with quote

Apprentice

Joined: 26 Jan 2016
Posts: 46

Thank you very much, this also works and I can handle it individually
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 » How to add value/name in JSON
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.