Python Forum
convert a json file to a python dictionnary of array
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
convert a json file to a python dictionnary of array
#3
(Sep-10-2019, 10:26 AM)buran Wrote: what have you tried? Note that so called json that you have is not valid one. it looks like already converted to JSON object in python

thanks Buran,
i find out this solution
from collections import defaultdict

data = [{'_id': '1', 'date': '2019-09-07', 'name': 'abi', 'value': 0, 'unit': '°C'},
{'_id': '2', 'date': '2019-09-08', 'name': 'allo', 'value': 3, 'unit': '°F'},
{'_id': '3', 'date': '2019-09-09', 'name': 'ali', 'value': 0, 'unit': '°C'}]

result = defaultdict(list)
for i in data:
    for k, v in i.items():
        result[k].append(v)
print(result)
Reply


Messages In This Thread
RE: convert a json file to a python dictionnary of array - by Reims - Sep-10-2019, 01:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  encrypt data in json file help jacksfrustration 1 239 Mar-28-2024, 05:16 PM
Last Post: deanhystad
Question [SOLVED] Correct way to convert file from cp-1252 to utf-8? Winfried 8 921 Feb-29-2024, 12:30 AM
Last Post: Winfried
  Convert numpy array to image without loading it into RAM. DreamingInsanity 7 5,917 Feb-08-2024, 09:38 AM
Last Post: paul18fr
  parse json field from csv file lebossejames 4 772 Nov-14-2023, 11:34 PM
Last Post: snippsat
  Convert File to Data URL michaelnicol 3 1,186 Jul-08-2023, 11:35 AM
Last Post: DeaD_EyE
  Convert np Array A to networkx G IanAnderson 2 698 Jul-05-2023, 11:42 AM
Last Post: IanAnderson
  Python Script to convert Json to CSV file chvsnarayana 8 2,554 Apr-26-2023, 10:31 PM
Last Post: DeaD_EyE
  Loop through json file and reset values [SOLVED] AlphaInc 2 2,153 Apr-06-2023, 11:15 AM
Last Post: AlphaInc
  How do I add comments from a text-file to an array of folders? clausneergaard 2 1,803 Feb-08-2023, 07:45 PM
Last Post: Larz60+
  Converting a json file to a dataframe with rows and columns eyavuz21 13 4,558 Jan-29-2023, 03:59 PM
Last Post: eyavuz21

Forum Jump:

User Panel Messages

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