0

I am having 6 python lists as follows:

dows=['Mon', 'Tue', 'Wed', 'Thu', 'Fri']
dates=['10-4', '10-5', '10-6', '10-7', '10-8']
maxs=['24', '23', '17', '16', '18']
mins=['13', '13', '11', '10', '7']
precipitation_probabilities=['0', '0', '76', '70', '21']
wind_speeds=['13', '21', '16', '8', '11']

and like to convert them to json, which I want eventually save to a drive as a file (on rasppberry pi) in format as follows:

{
    "dows":['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],
    "dates":['10-4', '10-5', '10-6', '10-7', '10-8'],
    "maxs":['24', '23', '17', '16', '18'],
    "mins":['13', '13', '11', '10', '7'],
    "precipitation_probabilities":['0', '0', '76', '70', '21'],
    "wind_speeds":['13', '21', '16', '8', '11']
}

I've tried everything without luck.

0

1 Answer 1

2

IIUC, you just want the following python dict:

my_dict = {"dows": dows, 
           "dates": dates, 
           "maxs": maxs, 
           "mins": mins, 
           "precipitation_probabilities": precipitation_probabilities,
           "wind_speeds": wind_speeds}

To get the json string representation of the above dictionary:

import json
my_json = json.dumps(my_dict)

To write the dictionary to a json file:

with open('output.json', 'w') as outfile:
    json.dump(my_dict, outfile)
Sign up to request clarification or add additional context in comments.

1 Comment

OMG! This easy? No way. I've spent like hours of googling and trying. Thank you!

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.