Python Forum
Write a dictionary with arrays as values into JSON format
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Write a dictionary with arrays as values into JSON format
#1
Hi

I'm working with dictionaries where values are (numpy) arrays, and I'm trying to figure out how to export these dictionaries in an JSON format, and how to read it afterward.

I'm not familiar with JSON specifications and that's why I'm facing some issues : does somebody can advice me on docs to read 'and fto fill my lacks) involving dictionnaries and arrays?

Thanks

Paul

In the following code, only an array is tested
## to write Json file
b = np.ndarray.tolist(MyArray)
json.dump(b, codecs.open(PATH + '/export.json', 'w', encoding='utf-8'), separators=(',', ':'), sort_keys=True, indent=4)

## to read it afterward
with open(PATH + '/export.json', "r") as JsonArray:
    json.load(JsonArray)
Error:
TypeError: the JSON object must be str, bytes or bytearray, not TextIOWrapper
Reply


Messages In This Thread
Write a dictionary with arrays as values into JSON format - by paul18fr - Oct-12-2021, 06:22 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Write from dictionary to excel divon 3 3,475 Jun-11-2023, 10:37 AM
Last Post: Larz60+
  comparing floating point arrays to arrays of integers in Numpy amjass12 0 1,613 Jul-26-2021, 11:58 AM
Last Post: amjass12
  How to compare two json and write to third json differences with pandas and numpy onenessboy 0 4,640 Jul-24-2020, 01:56 PM
Last Post: onenessboy
  Numpy arrays and compatability with Fortran arrays merrittr 0 1,850 Sep-03-2019, 03:54 AM
Last Post: merrittr
  Merge JSON files prioritizing the updated values from most recent file nebulae 0 2,520 Apr-17-2019, 10:15 AM
Last Post: nebulae
  Trying to import JSON data into Python/Pandas DataFrame then edit then write CSV Rhubear 0 4,075 Jul-23-2018, 09:50 PM
Last Post: Rhubear

Forum Jump:

User Panel Messages

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