Converting JSON to XML(atom)

955 views
Skip to first unread message

computerzworld

unread,
Aug 21, 2008, 4:14:03 AM8/21/08
to Google Contacts API
Hello,
I am having the contact list in JSON format and I want to convert it
into XML Atom format using PHP. Is it possible to convert JSON to XML?
If yes then how? Please help me. Thanks in advance.

Trevor Johns

unread,
Aug 21, 2008, 8:33:27 PM8/21/08
to google-co...@googlegroups.com

Hello computerzworld,
Is there a reason you don't just request the Atom feed in the first
place, rather than attempting to convert the JSON feed?

--
Trevor Johns

computerzworld

unread,
Aug 21, 2008, 11:12:34 PM8/21/08
to Google Contacts API
actually I am having JSON format as response from other service and I
want to send it to google so it is required to convert it back to xml
for giving back it to google. That's why I need to convert it.

On Aug 22, 5:33 am, "Trevor Johns" <tjo...@google.com> wrote:

Trevor Johns

unread,
Aug 22, 2008, 4:45:25 PM8/22/08
to google-co...@googlegroups.com
On 8/21/08, computerzworld <meat...@gmail.com> wrote:
>
> actually I am having JSON format as response from other service and I
> want to send it to google so it is required to convert it back to xml
> for giving back it to google. That's why I need to convert it.

Ah, I see.

Unfortunately, there's no easy answer here. The only way that I know
of to do this is to walk through the JSON and manually create the
corresponding XML (either directly or using one of the client
libraries).

--
Trevor Johns

computerzworld

unread,
Aug 26, 2008, 12:36:10 AM8/26/08
to Google Contacts API
oh I see. but is there any possiblity to provide our json data to any
php class that will convert our json into XML?

On Aug 23, 1:45 am, "Trevor Johns" <tjo...@google.com> wrote:

Trevor Johns

unread,
Aug 26, 2008, 3:57:46 AM8/26/08
to google-co...@googlegroups.com
On 8/25/08, computerzworld <meat...@gmail.com> wrote:
>
> oh I see. but is there any possiblity to provide our json data to any
> php class that will convert our json into XML?

The problem is that JSON doesn't directly translate to XML. There's
features in each that aren't available in the other.

That's not to say it can't be done. But how it's done will depend on
the specifics of the situation: what you have as input, and what you
want as output.

Here's an article that discusses converting from XML to JSON (and vice
versa) just to give you an idea of the issues involved:

http://onwebdevelopment.blogspot.com/2008/05/converting-xml-to-json.html

As you can see, while it's possible, there's no standard way of handling this.

Now, there is some code out there that attempts to do this conversion
for you, provided you adhere to certain rules. The article above had
some JavaScript code to do this. I'm not familiar with any for PHP,
but I do know of a .NET one:

http://james.newtonking.com/archive/2006/07/11/656.aspx

If your data doesn't fit within their rules, or if you can't find a
PHP library, you'll need to write something yourself. At the very
least, there are classes in PHP that know how to parse XML and JSON.
You just have to write the rules to map between the two.

--
Trevor Johns

Reply all
Reply to author
Forward
0 new messages