Python Forum
.JSON conversion to .CSV or .xslx - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: .JSON conversion to .CSV or .xslx (/thread-9131.html)



.JSON conversion to .CSV or .xslx - tccompton - Mar-22-2018

I'm currently undertaking my masters thesis and recording lots of data (through in-house software) which churn out files in .JSON format. Any ideas of coding a way to convert this data directly into either .CSV or .xslx files?

Would save me so much time copying and pasting!

Thanks in advance. Smile


RE: .JSON conversion to .CSV or .xslx - buran - Mar-22-2018

well, sample data will help
but general advice is to look at json module and csv module from standard library. there are also third-party packages that may help depending on data


RE: .JSON conversion to .CSV or .xslx - tccompton - Mar-22-2018

Of course, my mistake.
I'll have a look on them, thank you.

I don't have the code from Pithy to get the data in this format (someone else wrote it) - but this is how the data comes out in .JSON :

The idea is then to plot this data on a simple x-y graph on MATLAB (via excel through a lot of copy and pasting at the moment).


RE: .JSON conversion to .CSV or .xslx - Gribouillis - Mar-22-2018

I don't think it is json syntax, although there appears to be a collection of key/value pairs and a ordered list of values.


RE: .JSON conversion to .CSV or .xslx - snippsat - Mar-23-2018

As mention it's not json,but more a key/value kind of data.
Then can write a example that fit's this data fine which is a dictionary.
d = {}
with open('2.txt') as f:
    for line in f:
        line = line.split()
        if line == ['amp']:
            d['amp'] = None
        else:
            d[line[0]] = line[1].replace('"', '')
A look at some data in dictionary,bye slicing out some values.
>>> import itertools
>>> dict(itertools.islice(d.items(), 0, 8))
{'BaseGain': '70',
 'Channel1': '1',
 'Channel2': '1',
 'Delay': '0',
 'Freq': '5',
 'Name': 'sanitycheck',
 'Range': '6',
 'TransmissionMode': 'PE'}
Quote:The idea is then to plot this data on a simple x-y graph on MATLAB (via excel through a lot of copy and pasting at the moment).
Python has strong tools for this,that's can replace MATLAB and Excel.
Here a quick demo with plot of some of your data(islice(d.items(), 60, 80)) using Matplotlib and Jupyter Notebook.
Also look at Pandas that can do same stuff as Excel,
and also easy to transport to Excel df.read_excel() and df.to_excel().
[Image: YzFDWu.jpg]