JSon To XML Converter RPG

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
mpilo0
Profound User
Posts: 49
Joined: Wed Jan 08, 2014 11:49 am
First Name: Michael
Last Name: Pilote
Company Name: Oceanex
Phone: (514) 875-8558
State / Province: Quebec
Country: Canada
Contact:

JSon To XML Converter RPG

Post by mpilo0 »

Hi,
Is there a way to convert JSON to XML and vice-versa using RPG? We are making Web services and we want to return XML. However, many of the programs we use, such as Profound UI, use the JSON format. We would like to be able to pass a parameter to our RPG Web service container that would allow us to determine what type of output we want without adding dependencies to a JVM or another server.
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: JSon To XML Converter RPG

Post by Scott Klement »

I suppose it would be possible to convert JSON to XML or vice-versa. But, it still seems to me that you'd need to write a separate web service for each thing you wanted to do, so this really doesn't save you much?

Profound UI can call a web service that outputs JSON, but that JSON has to be in a specific format. It has to contain particular items (JSON arrays containing objects with particular field names, etc.) I've never seen an XML web service that wants the exact same field names in the same places. So it seems to me that you'd need to write a web service that returns the appropriate field names in the appropriate places for whatever purpose you are trying to serve, whether the output is JSON or XML is only a small part of the differences you'd need to handle for different callers.

Since you'd need to write a separate service anyway (to produce the proper field names in the proper structure) you might as well have the separate service output the proper format (JSON or XML) that the caller is expecting. It's hard to see how converting between JSON and XML would help?
mpilo0
Profound User
Posts: 49
Joined: Wed Jan 08, 2014 11:49 am
First Name: Michael
Last Name: Pilote
Company Name: Oceanex
Phone: (514) 875-8558
State / Province: Quebec
Country: Canada
Contact:

Re: JSon To XML Converter RPG

Post by mpilo0 »

The reason we wanted to do this is because we currently use XML-INTO to parse XML. We didn't have a way to do the same for JSON so we wanted to convert it into JSON at the end, if required. However, we just came across YAJL that would allow us to do just that. We are looking into it at the moment with the front-end layer that you built. Do you think you will have any documentation on the parser you built?

Thank you
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: JSon To XML Converter RPG

Post by Scott Klement »

Unfortunately, I haven't had time to write documentation on YAJL, yet. I have been asked to write both articles and presentations on YAJL, some of which are overdue, but I haven't had time, things have been busy. Business at Profound has been booming (we've been breaking/setting records for sales, hiring new people, etc... a good problem to have!)

I could help you by answering questions here, though.

However, I can't think of any place that you'd need to parse JSON in Profound UI. Profound UI will call your RPG program, but it does not send you a JSON document, rather it expects you to output a JSON document. You could use YAJL to generate that document (or you could use another means, such as CGIDEV2, or just coding it in your RPG program). But I can't think of a situation where you'd need to read JSON?

There is an article that I published about how to generate JSON with YAJL, here:
http://iprodeveloper.com/rpg-programmin ... g-and-yajl
mpilo0
Profound User
Posts: 49
Joined: Wed Jan 08, 2014 11:49 am
First Name: Michael
Last Name: Pilote
Company Name: Oceanex
Phone: (514) 875-8558
State / Province: Quebec
Country: Canada
Contact:

Re: JSon To XML Converter RPG

Post by mpilo0 »

The reason for doing this is that we may have some web services that will be used for updates. They will receive a JSON string in that we will process and update the tables in the back end. We want to standardize our web services so that they do not receive XML and output JSON. We dont want to process it directly in RPG because these web services would be used by both Profound and other platforms(such as our website).
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests