Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help Parsing JSON
#5
don't use json as name, it's a built-in module and you don't want to override it

data = {
    "12345": {
        "2021-01-20": {
            "a": 1,
            "b": 3,
            "c": 0
        },
        "2021-01-21": {
            "a": 1,
            "b": 3,
            "c": 0
        }
    },
    "12346": {
        "2021-01-20": {
            "a": 1,
            "b": 3,
            "c": 0
        },
        "2021-01-21": {
            "a": 1,
            "b": 3,
            "c": 0
        }
    }
}

for product, dates in data.items():
    for adate, values in dates.items():
        print(f"{product},{adate},{values['a']},{values['b']},{values['c']}")
Output:
12345,2021-01-20,1,3,0 12345,2021-01-21,1,3,0 12346,2021-01-20,1,3,0 12346,2021-01-21,1,3,0
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
Help Parsing JSON - by kfwydfo1x - Jan-25-2021, 12:57 PM
RE: Help Parsing JSON - by buran - Jan-25-2021, 01:12 PM
RE: Help Parsing JSON - by kfwydfo1x - Jan-25-2021, 01:29 PM
RE: Help Parsing JSON - by DeaD_EyE - Jan-25-2021, 01:33 PM
RE: Help Parsing JSON - by buran - Jan-25-2021, 01:44 PM
RE: Help Parsing JSON - by DeaD_EyE - Jan-26-2021, 10:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Parsing large JSON josvink66 5 1,986 Jan-10-2024, 05:46 PM
Last Post: snippsat
  Parsing JSON pyStund 4 6,134 Jul-31-2022, 02:02 PM
Last Post: pyStund
  Json Parsing sshree43 5 2,914 May-04-2022, 09:21 PM
Last Post: snippsat
  json api data parsing elvis 0 1,335 Apr-21-2022, 11:59 PM
Last Post: elvis
  string indices must be integers when parsing Json ilknurg 3 9,886 Mar-10-2022, 11:02 AM
Last Post: DeaD_EyE
  Parsing JSON with backslashes bazcurtis 3 11,594 Feb-08-2020, 01:13 PM
Last Post: bazcurtis
  JSON parsing (nested) fakka 0 3,612 Nov-25-2019, 09:25 PM
Last Post: fakka
  Parsing json - dictionary with in dictionary krish216 6 4,652 Jul-30-2019, 10:01 PM
Last Post: cvsae
  JSON Parsing PythonLearner007 3 3,242 Jan-31-2019, 10:47 AM
Last Post: gontajones

Forum Jump:

User Panel Messages

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