The Python Oracle

django JSONField doesn't accept value

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: RPG Blues Looping

--

Chapters
00:00 Django Jsonfield Doesn'T Accept Value
00:54 Accepted Answer Score 7
01:41 Thank you

--

Full question
https://stackoverflow.com/questions/6553...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #django

#avk47



ACCEPTED ANSWER

Score 7


This is not valid JSON. The strings in JSON are wrapped with double quotes. Indeed, you can verify this for example with JSONLint.com. It is a valid Python dictionary, but not valid JSON.

You thus should enter:

{ "key": "value" }

For more information, see the JSON specifications.

I add products in admin panel. I want to have multiple attributes for my products like color , size and ... . is it true to use json fiels for that??

If the fields are fixed (are attributes of all Products), then you should use individual fields, since that is more convenient to fielter, make forms, etc. If the data is more dynamic, it is often better to make use of a JSON field.