Don’t use single quotes in JSON

莊子弘
1 min readJan 22, 2021

--

Recently, I used python to deal some JSON data.
When I used a python builtin module — json to extract a json format data (in my opinion), it reported this error:

json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes

You can try it by yourself:

import jsonjj = "{'a': 0}"
e = json.loads(jj)
print(e)

The reason of error is : “single quote is not supported in JSON format”

you can see these 2 sentences in json.org

A value can be a string in double quotes, or a number, or true or false or null, or an object or an array. These structures can be nested.

A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. A character is represented as a single character string. A string is very much like a C or Java string.

Also you can see these synonymous sentences in W3C.

Just a little sharing.

--

--

莊子弘
莊子弘

Written by 莊子弘

文字工作者,不過周一到週五寫的都是程式碼。閒暇時間會分享一些心得,包含技術文章或影集書籍觀後感。

No responses yet