Is there any difference in JSON Key when using single quote and double quote?
double-quotes, javascript, json
Solution
In JSON only double quotes are valid.
You can find the standard on 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.
In other words, no strings in single quotes.
Problem
I ran two pieces of javascript codes in a online JS running platform:Website Link ``` pets = '{'pet_names':[{"name":"jack"},{"name":"john"},{"name":"joe"}]}'; var arr = JSON.parse(pets); alert(arr.pet_names[1].name); ``` Code with double quotes ("pet_names") would be OK but with single quotes('pet_names') would remind a error:"Unexpected identifier" ``` pets = '{"pet_names":[{"name":"jack"},{"name":"john"},{"name":"joe"}]}'; var arr = JSON.parse(pets); alert(arr.pet_names[1].name); ``` So, why do it would happen?