0

I am new here , need some help with writing to json file:

I have a dataframe with below values, which is created by reading a excel file enter image description here

need to write this to json file with object as column dtls

Output :

enter image description here

2
  • If you have a specific issue while solving this yourself you can ask here with your code. Commented Feb 14, 2023 at 9:18
  • Show JSON and other textual information as properly formatted text in the question, not as comment, image or external link. Commented Feb 14, 2023 at 9:19

2 Answers 2

0

A similar task is considered in the question:

Converting Excel into JSON using Python

Different approaches are possible to solve this problem.

Sign up to request clarification or add additional context in comments.

Comments

0

I hope, it works for your solution.

import pandas as pd
import json
df = pd.read_excel('./TfidfVectorizer_sklearn.xlsx')
df.to_json('new_file1.json', orient='records') # excel to json
# read json and then append details to it
with open('./new_file1.json', 'r') as json_file: 
    a = {}
    data = json.load(json_file)
    a['details'] = data
# write new json with details in it
with open("./new_file1.json", "w") as jsonFile:
    json.dump(a, jsonFile)

JSON Output:

enter image description here

2 Comments

i am not able to get an object name in the output .for example "Details" is missing in the final output
Kindly look at my updated code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.