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 message creation unlike standard modelling

Post new topic  Reply to topic
 JSON message creation unlike standard modelling « View previous topic :: View next topic » 
Author Message
mayheminMQ
PostPosted: Fri May 27, 2016 12:46 am    Post subject: JSON message creation unlike standard modelling Reply with quote

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
View user's profile Send private message
fjb_saper
PostPosted: Fri May 27, 2016 2:15 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20696
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
View user's profile Send private message Send e-mail
mayheminMQ
PostPosted: Fri May 27, 2016 2:38 am    Post subject: Reply with quote

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
View user's profile Send private message
mqjeff
PostPosted: Fri May 27, 2016 4:02 am    Post subject: Reply with quote

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
Code:
Item[1]

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
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 message creation unlike standard modelling
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.