1

I am trying to create a json file which reads data from test.xlsx. My sample code is below.

Instead of "WO-12345" and other values, I want that to be read from the excel sheet, like I want it to be read from a particular cell in excel.

import xlrd
from collections import OrderedDict
import simplejson as json
import json

jsonfile = open('data1.json', 'w')
data_list = []
data = OrderedDict()

data['workOrder'] = "WO-12345"
data['alternateStart'] = "2018-01-13T10:00:00Z"
data['mobileNumber'] = "(555) 555-5555"
data['officeNumber'] = "(555) 555-5554"
data['description'] = "Testing"
data['equipment'] = "Testing"

data_list.append(data)

j = json.dumps(data_list)


json.dump(data, jsonfile, indent=3, sort_keys=False)
jsonfile.write('\n')
1

1 Answer 1

3

If you want to read an Excel there's pandas pandas.read_excel, it returns a pandas.DataFrame that has the to_json method.

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html

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

Comments

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.