#πŸ”’ Im trying to append dictionaries to a json file but dont know how to seperate them.

27 messages Β· Page 1 of 1 (latest)

dusk badge
#

JSON standard allows only one top-level value This is the error that comes up in the file.

idle auroraBOT
#

@dusk badge

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

graceful plover
#

you would load the json, update the dict, then write it out again

dusk badge
#

update the dict im trying to add ?

graceful plover
#

it depends on how you want your data structured

#

you can have a list of dicts if you want

#

that way you can "append" to the json data by appending to the list

dusk badge
#

yeah im trying to have a big list that has dicts in it

humble portal
#

so your JSON would look like [{...}, {...}, ...]

graceful plover
#

then that should work fine

teal anchor
#

you should use sqlite

dusk badge
#

i dont know what that is

#

im a beginner to python

#

im just trying to store information thats in dictionaries and be able to access them later

teal anchor
dusk badge
#

im not trying to over complicate it tho rn

teal anchor
#

shelve will be the simplest then

dusk badge
#

the file is only being updated when the function finishes its loop

#

wouldnt just having a json file be easier to access later and such

teal anchor
#

sqlite would be ideal

dusk badge
#

ill look into it

#

thanks

idle auroraBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.