Author |
Message
|
mr2kn |
Posted: Fri Feb 12, 2016 12:05 pm Post subject: How to add value/name in JSON |
|
|
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 |
|
 |
maurito |
Posted: Fri Feb 12, 2016 11:25 pm Post subject: Re: How to add value/name in JSON |
|
|
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 |
|
 |
stoney |
Posted: Sat Feb 13, 2016 4:27 am Post subject: Re: How to add value/name in JSON |
|
|
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 |
|
 |
mr2kn |
Posted: Sun Feb 14, 2016 9:57 am Post subject: |
|
|
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 |
|
 |
stoney |
Posted: Sun Feb 14, 2016 10:10 am Post subject: |
|
|
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 |
|
 |
timber |
Posted: Mon Feb 15, 2016 2:18 am Post subject: |
|
|
 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 |
|
 |
mqjeff |
Posted: Mon Feb 15, 2016 5:54 am Post subject: |
|
|
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 |
|
 |
mr2kn |
Posted: Mon Feb 15, 2016 7:51 am Post subject: |
|
|
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 |
|
 |
mgk |
Posted: Mon Feb 15, 2016 1:14 pm Post subject: |
|
|
 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 |
|
 |
mr2kn |
Posted: Tue Feb 16, 2016 6:46 am Post subject: |
|
|
Apprentice
Joined: 26 Jan 2016 Posts: 46
|
Thank you very much, this also works and I can handle it individually |
|
Back to top |
|
 |
|