#1 2013-05-17 10:04:11

sal
Member
Registered: 2013-05-17
Posts: 10

Interface example for transmitting complex JSON Object

Hi ,

I am new MorMot Framework , was trying out with samples provides with framework., interface example works for simple data types like integers and chars. but i am lost while i am trying to transmit complex JSON objects like the once specified below


Our teams intention is to transmit Complex JSON Strings with HTTP post method from Java client, we are evaluating different high performance server side framework to meet our requirements. i thought Interface based services samples would be right sample which more or less seems to be configured for 3-tier.

Please let me know if there are any other sample which closely aligns to our above requirement, our JSON is as stated below

{   
    "Airport" :  { 
         "Location" : "LAX" , 
         "Terminal" : ["terminalA", "terminalB", "terminalC"] ,
         "Gate"      : ["gate1", "gate2", "gate3", "gate4", "gate5" ],
         "BHS"       : "Siemens" ,
         "DCS"       : "Altiea" 
    },
    "Airline" : {
        "CX" : ["B777", "B737", "A380", "A320" ],
        "QR"  : ["A319", "A380", "B787" ],
        "ET"   : "380",
        "SQ"  : "A320"
    },
    "GroundHandler" : ["Swissport","SATS","Wings","TollData"]
}

I appreciate your quick response and let me know if any info is needed.

regards
Sal

Offline

#2 2013-05-17 15:20:02

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,272
Website

Re: Interface example for transmitting complex JSON Object

Transmission is just the latest part of the process.
mORMot is perfectly able to transmit data as such.
But it will depend on how your DB model is handled.

There was no sample to be used directly for your purpose.

I've create a new one.
See http://synopse.info/fossil/info/47be920e62

You can try to consume the service using the following RESTful request:
POST   on   http://SERVERNAME:888/project20/AirportService.GetAirportDefinition
with body  equals to the '[1234]' text (i.e. the interface will transmit an ID=1234 paramerter to the remote service).

Then it will return the following content:

{
	"Airport": 
	[
		{
			"Location": "LAX",
			"Terminal": ["terminalA","terminalB","terminalC"],
			"Gate": ["gate1","gate2","gate3","gate4","gate5"],
			"BHS": "Siemens",
			"DCS": "Altiea"
		}
	],
	"Airline": 
	[
		{
			"CX": ["B777","B737","A380","A320"],
			"QR": ["A319","A380","B787"],
			"ET": "380",
			"SQ": "A320"
		}
	],
	"GroundHandler": ["Swissport","SATS","Wings","TollData"]
}

Offline

#3 2013-05-19 08:26:18

sal
Member
Registered: 2013-05-17
Posts: 10

Re: Interface example for transmitting complex JSON Object

Hi,

Thanks for your prompt and quick reply. I will try your sample on Java Client . can you please provide more clarity on following items


1. What you mean by DB Model in your statement  "But it will depend on how your DB model is handled" , the reason is to know if there are any particular model to be used for certain kind of transaction. some reference to this topic would be really helpful to understand in detail.

2. How can I build similar JSON string as below from my Delphi client , because I find AddJsonEscape() function depends on particular template. is there any flexible mechanism to build complex JSON object or string at client side.

{
    "Airport":
    [
        {
            "Location": "LAX",
            "Terminal": ["terminalA","terminalB","terminalC"],
            "Gate": ["gate1","gate2","gate3","gate4","gate5"],
            "BHS": "Siemens",
            "DCS": "Altiea"
        }
    ],
    "Airline":
    [
        {
            "CX": ["B777","B737","A380","A320"],
            "QR": ["A319","A380","B787"],
            "ET": "380",
            "SQ": "A320"
        }
    ],
    "GroundHandler": ["Swissport","SATS","Wings","TollData"]
}


Thanks again for your feedback

regards
Sal

Offline

#4 2013-05-19 12:01:38

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,272
Website

Re: Interface example for transmitting complex JSON Object

1. Download and check the SAD 1.18 pdf.
You will find useful info here.

2. The new sample I wrote for you generates just this kind of JSON.

Offline

#5 2013-05-20 09:25:07

sal
Member
Registered: 2013-05-17
Posts: 10

Re: Interface example for transmitting complex JSON Object

Hi,

I am able to receive following JSON string  from client , I want to parse into individual elements in 2 levels.

string jsondata =
{   
    "Airport" :  {
         "Location" : "LAX" ,
         "Terminal" : ["terminalA", "terminalB", "terminalC"] ,
         "Gate"      : ["gate1", "gate2", "gate3", "gate4", "gate5" ],
         "BHS"       : "Siemens" ,
         "DCS"       : "Altiea"
    },
    "Airline" : {
        "CX" : ["B777", "B737", "A380", "A320" ],
        "QR"  : ["A319", "A380", "B787" ],
        "ET"   : "380",
        "SQ"  : "A320"
    },
    "GroundHandler" : ["Swissport","SATS","Wings","TollData"]
}




I want to parse this JSON object in 2 levels


first level , values of :  "Airport" , "Airline" , "GroundHandler"  elements  should be parsed into separate arrays or objects

second level , values of : "Location", "Terminal", "Gate","BHS","DCS","CX","QR","ET","SQ"  should be parsed into separate set of arrays or objects


I tried with JSONDecode, JSONToObject,  GetJSONField functions , but am not able to get desired results .

Can you please help with sample mechanisms to get this parsed or do I need to use any other Delphi JSON parsers to accomplish my requirement


Thanks and regards
Sal

Offline

#6 2013-05-20 10:31:46

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,272
Website

Re: Interface example for transmitting complex JSON Object

I do not follow you well.

You asked for Delphi server side, and now you are asking for Delphi clients?

If you use a Delphi client, you already have the corresponding client project within the sample folder.
You do not need to parse the content, since the object is already there, with all nested internals and arrays.

  Airport := TDTOAirportDefinition.Create;
  try
    I.GetAirportDefinition(id,Airport);
    // here you have all Airport members containing the data
    for n := 0 to high(Airport.AirLine.CX) do
      ...
  finally
    Airport.Free;
  end;

If you want to get rid of the two arrays, you have to get rid of the two TCollection and replace them with good old TPersistent classes.

Offline

#7 2013-05-20 13:24:39

sal
Member
Registered: 2013-05-17
Posts: 10

Re: Interface example for transmitting complex JSON Object

Hi,

Sorry if it was confusing , I didn't ask for client side . 


Client is sending below JSON string to Server .

string jsondata =
{   
    "Airport" :  {
         "Location" : "LAX" ,
         "Terminal" : ["terminalA", "terminalB", "terminalC"] ,
         "Gate"      : ["gate1", "gate2", "gate3", "gate4", "gate5" ],
         "BHS"       : "Siemens" ,
         "DCS"       : "Altiea"
    },
    "Airline" : {
        "CX" : ["B777", "B737", "A380", "A320" ],
        "QR"  : ["A319", "A380", "B787" ],
        "ET"   : "380",
        "SQ"  : "A320"
    },
    "GroundHandler" : ["Swissport","SATS","Wings","TollData"]
}



Now server receives the JSON string successfully . after receiving I want to break (parse) the received JSON string into individual components(strings) as below. with JSONDecode , JSONToObject functions , I am not able to parse the JSON string successfully , so I wanted to know if mORMoT Framework supports complex JSON parsing or do we need to use other JSON parsing libraries (eg TinyJSON, SuperObject etc) .  if mORMot framework supports complex JSON object parsing, I appreciate if you could provide link to an example.


string Airport := '{
         "Location" : "LAX" ,
         "Terminal" : ["terminalA", "terminalB", "terminalC"] ,
         "Gate"      : ["gate1", "gate2", "gate3", "gate4", "gate5" ],
         "BHS"       : "Siemens" ,
         "DCS"       : "Altiea"
    }'

string Airline := '{
        "CX" : ["B777", "B737", "A380", "A320" ],
        "QR"  : ["A319", "A380", "B787" ],
        "ET"   : "380",
        "SQ"  : "A320" }

string groundhandler = '["Swissport","SATS","Wings","TollData"] '


Hope you understood the probem.

regards
Sal

Offline

#8 2013-05-20 13:29:14

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,272
Website

Re: Interface example for transmitting complex JSON Object

In fact, it is not complex JSON parsing, it is JSON by-passing. smile

You can use the GotoNextJSONObjectOrArray() function to retrieve the JSON buffer content of any member.

Offline

#9 2013-05-20 13:37:49

sal
Member
Registered: 2013-05-17
Posts: 10

Re: Interface example for transmitting complex JSON Object

Do you mean , I need to use GotoNextJSONObjectOrArray()  to do parsing of below JSON string . do you have any sample code for reference.

May be i am lost in initialization part or may be I am doing something wrong basically.

regards
Sal

Offline

#10 2013-12-06 21:49:56

foncci
Member
Registered: 2013-11-15
Posts: 53

Re: Interface example for transmitting complex JSON Object

Hi, ab

I was checking out the source but I couldn't find where you define that you handle the POST method not where to read the body. Can you tell me where you you read it?

Regards,

Al

Offline

#11 2013-12-06 22:50:26

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,272
Website

Re: Interface example for transmitting complex JSON Object

It is difficult to find out what you are talking about...

Offline

Board footer

Powered by FluxBB