The Python Oracle

django JSONField doesn't accept value

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Music Box Puzzles

--

Chapters
00:00 Question
01:13 Accepted answer (Score 5)
02:14 Thank you

--

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

Question links:
[image]: https://i.stack.imgur.com/8Il1d.png

Accepted answer links:
[JSONLint.com]: https://jsonlint.com/
[JSON specifications]: https://www.json.org/json-en.html

--

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.