merging multiple jsons into one with data export

27 views Asked by At

I have a folder containing multiple json files with a data like:

file1

myname, myname2, myname3, myname, myname, myname3,


file 2 myname5, myname, myname2, myname5, myname3, myname3,

I want a file that give my something like this:

myname, 4, myname2, 2, myname3, 4, myname5, 2,

in a nutshell, it should could all occurrences of a text and export how many numbers it repeated.

I want to know how can I achieve this, what language? is it possible to do it in cloud?

1

There are 1 answers

1
Xavier On

its not very clear what you want. if you put more details on your question maybe we can work on a better answer. If possible provide a complete example of the json file.

But if I understood correctly what you need. I think it can easily be done in python.

Example of code:

import pandas as pd

FileWithAllData = {}


myname_df = pd.read_json(".../file1.json")
myname_df = myname_df.groupby(['columns_with_the_names', as_index=False).agg('count')[['columns_with_the_names','columns_with_quantity"]]

myname_df = myname_df.to_dict(orient='records')

#Saving as json file

import json
js = json.dumps(myname_df)

# Open new json file if not exist it will create
fp = open('myname_df.json', 'myname_df')

# write to json file
fp.write(js)

# close the connection
fp.close()

Now you have a json file were they keys are the names and the corresponding values is the number of times they are repeated.

I hope it helps you.