|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
JSON message creation unlike standard modelling |
« View previous topic :: View next topic » |
Author |
Message
|
mayheminMQ |
Posted: Fri May 27, 2016 12:46 am Post subject: JSON message creation unlike standard modelling |
|
|
 Voyager
Joined: 04 Sep 2012 Posts: 77 Location: UK beyond the meadows of RocknRoll
|
Hi All,
Requirement : The customer at end point requires a JSON message of the following format.
Code: |
[
"Customer" : {
"CustomersName" : "BHAMBHAM"
},
"Orders" : [{
"Order" : {
"OrderDate" : "27/04/2015 09:56:49 BST"
}
}
]
,
"Payment" : {
"Statusofpayment" : "Awaiting Security Check"
}
] |
What have I done:
I created a happy esql mapping code from a request which is XML and wrote lines of code to map and model the json message.
Since the message starts with the top level element as an array, I started of my creation with
Code: |
SET OutputRoot.JSON.Data TYPE = JSON.Array; |
Within the data array, I then created the 3 children which are Customer, Orders and Payment.
Code: |
CREATE LASTCHILD OF OutputRoot.JSON.Data.Customer AS outCustRef NAME 'Customer';
CREATE FIELD OutputRoot.JSON.Data.list.Orders IDENTITY(JSON.Array)Orders;
SET OutputRoot.JSON.Data.Item[1].Payment[].Statusofpayment= blah blah
|
Problem:
My output comes out after the field level mappings but it has a { before every primary children.
Code: |
[
{"Customer" : {
"CustomersName" : "BHAMBHAM
}},
{"Orders" : [{
"Order" : {
"OrderDate" : "27/04/2015 09:56:49 BST"
}
}
]
},
{"Payment" : {
"Statusofpayment" : "Awaiting Security Check"
}
}
] |
Notice the {} embedding between Customer, Orders and Payment.
I read through various JSON related posts and in knowledge centre and I am yet to find a sample message that achieves the original requirement message style.
What do I seek:
the original requirement is not passing JSON validator(one of the sites found online JSONLint) while the one created by me is validated correctly.
So, if I am forced to create the message as per requirement, then is the way to go through string manipulation post serialising the message or can I achieve this by doing something dirty in esql. _________________ A Colorblind man may appear disadvantaged but he always sees more than just colors... |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri May 27, 2016 2:15 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
That's what I thought...
Your JSON starts with [ and ends with ]
This is not right. Replace the start and end char with { and } and your JSON is valid!
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
mayheminMQ |
Posted: Fri May 27, 2016 2:38 am Post subject: |
|
|
 Voyager
Joined: 04 Sep 2012 Posts: 77 Location: UK beyond the meadows of RocknRoll
|
fjb_saber, I think you are wrong here as JSON can start as an array instead of just an object.
The JSONvalidator bombed the mentioned json as it did not have { before Customers/Orders/Payment.
Valid JSON
Code: |
[ {Customer{Name:AAA},{Title:Mr}},{Order{Ordernumber:1111}}]
|
Invalid JSON
Code: |
[ Customer{Name:AAA},{Title:Mr},Order{Ordernumber:1111}] |
_________________ A Colorblind man may appear disadvantaged but he always sees more than just colors... |
|
Back to top |
|
 |
mqjeff |
Posted: Fri May 27, 2016 4:02 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You might have to adjust the JSON type of each field - like you did with the JSON.Array for the top element.
Also, I'm not sure about the
That seems like it's creating another child of your array. Which is kinda the problem you're having... _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|