How To Convert Excel Spreadsheet to JSON

We’ve covered a neat trick that leverages Google spreadsheet as a JSON back-end service API for developers who are making any REST applications. However, the use case of this trick is limited if not difficult to adapt in production applications. Often times there is a layer gap within the raw data format between product managements to end developers. Business people tend to use Microsoft office products to store and exchange information, but when those data needs to be used in a product converting to a different format like JSON the process could be tedious. I’ve personally experienced this, and have found a great solution to help automate any Excel spreadsheet data into customized JSON formats.

This is a step-by-step guide on how to convert any Excel spreadsheet into JSON formats leverage Excel’s Developer features

First, we need to enable Developer tab if you haven’t enabled yet. Go to the start page > Options

2015-02-09_1018

Under Excel Options > Customize Ribbon > Developer. Make sure on the right column, Customize the Ribbon the Developer tab is checked.

2015-02-09_0933

Now, you will see a new tab called “DEVELOPER” showing, click to expand the menu and click Source. This will launch and expand the XML Source configurations. Click XML Maps … to bring up XML sample datasets or XML schema file (.xsd).

Now, it’s important to understand what’s going on here. We are trying to tell Excel to use XML schema to map the data from spreadsheet columns to the data expected from the XML schema. You don’t need to have a .xsd schema file ready, in fact, the easiest way to tell Excel what your data are going to look like is to create a sample XML with at least two repeated nodes.

2015-02-09_1019

Below is an example of a sample XML that contains a repeated item, each will have a model and description field. This is extremely simple to create and whole lot easier than dig your head into XML schema and learning all the new sets of syntax, which itself could take days.

<xml version=”1.0″ encoding=”UTF-8″ ?>
<items>
<item>
<model>MODEL_ID_100</model>
<description>model descriptions</description>
</item>
<item>
<model>MODEL_ID_101</model>
<description>model descriptions</description>
</item>
</items>
</xml>

2015-02-09_1020

Now click “Add..” to include the sample XML we’ve just created.

2015-02-09_10222015-02-09_1022_001

At this point, Excel detected that this is not a XML schema, but it understands this is a valid XML and it will generate a schema for us to use based on this sample.xml.

2015-02-09_1026

Once you have clicked OK. Excel will show you the generated schema with its corresponding names, root and namespace etc.

2015-02-09_1028

Now all you need to do is drag the filed into corresponding columns. OR you can right-click on the model and select the range of elements map to.

2015-02-09_10292015-02-09_1029_001

What you get after you have successfully mapped the columns is something like above, you will be able to sort and do all kinds things with those data. What we want is to export it into a valid XML file. You can do so by going to DEVELOPER tab and click “Export“.

2015-02-09_1030

This will export the data into a XML file and from this point on your life should be much easier. There are online tools out there would help you to convert the XML into JSON. Below is a screenshot that uses http://codebeautify.org/ to convert the XML from Excel schema mapping into JSON.

2015-02-09_1006

Hope you find this guide helpful, data conversions between legacy file formats to modern formats can be tedious and troublesome. I’m always a fan of automation, trying to find the right tool and leverage them coherently isn’t an easy task, but once you’ve masted them your life will be whole lot easier.

Jonathan Hu

Programming by day, Web Development, Canucks & Movies for spare time!
Co-founder of Next of Windows and a cool geek 🙂

Last updated: 02/10/2015

Posted in: How to , IT Pro
Discover more: , , ,

Leave a Reply

Notify of
avatar
wpDiscuz
Today's Top Picks for Our Readers:
Recommended by Recommended by NetLine