Python Forum
.JSON conversion to .CSV or .xslx
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
.JSON conversion to .CSV or .xslx
#1
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
Reply
#2
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
Reply
#3
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).
Reply
#4
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.
Reply
#5
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]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  first project read from xslx get only 1 column\row? korenron 9 3,757 Jun-13-2021, 07:21 AM
Last Post: korenron
  Conversion CSV to JSON mati 1 1,803 Jan-09-2021, 08:19 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020