Friday, June 10, 2011

XML / JSON Reader?

Have you ever encounter the problem of getting a XML file / grabbing a JSON object and you have problem reading the contents? If you have, this is a post for you.

For example, you have a xml file like the following:
How is it possible for a normal user be capable in understanding what information had been stored inside the XML file?

Well, here are a few simple solutions for you.
  1. Get yourself a browser like Mozilla Firefox or Google Chrome.
  2. Drag the XML file into the Mozilla Firefox or Google Chrome browser and voila.
Congratulations. You have got yourself a nicely formatted XML file.

And here are the images for your reference how the XML will look like in a Mozilla Firefox browser and a Google Chrome browser.

Mozilla Firefox Result
Google Chrome Result

Nowadays for and more API's are using JSON Objects to pass parameters around and Facebook's API would be one of the example of such an API.
Here's an example of how does a Raw JSON object will look like.
Well, here's a simple solution for you people out there.
  1. Get yourself the Mozilla Firefox Browser.
  2. Install this Mozilla Firefox extension known as Firebug.
  3. After all the crazy installation, open up your Mozilla Firefox browser and select 'Option' from the drop-down menu from the top of the browser.
  4. Select 'Firebug' and select 'Open Firebug', when the sub-menu appears.
  5. When the panel for 'Firebug' appears, select the option 'Console' from the top menu of the 'Firebug' panel.
  6. Next copy and paste the raw JSON object next to the '>>>' at the bottom left corner of the panel and press the button 'Enter' from your keyboard.

Congratulations. You should be getting something similar to the following.

Upon clicking on any one of the red/green links, you will be able to see a better view of the contents inside the JSON object, like the following screen grab.

Note: if the panel of 'Firebug' returns a 'SyntaxError: invalid label' error, try adding a '[' add the start of the JSON object and a ']' at the end of the JSON object and try pressiong the button 'Enter' on your keyboard again.

Here's a screen grab for your reference.

I hope that this post will help you to make your life easier in reading XML and JSON object.

No comments:

Post a Comment