Python Forum

Full Version: .JSON conversion to .CSV or .xslx
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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
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).
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.
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]