How do you display a field with an embedded quote

2019-07-29 23:31发布

问题:

JSON-LD fields are supposed to be double quoted

"name":  "value", 

but what if the value has an embedded double quote, like

"name" : "Magnetic Strip (36" Length)"

Is it sufficient to escape the double quote

"name" : "Magnetic Strip (36\" Length)"

or is there a better way?

回答1:

Yes, backslashes have to be used for escaping double quotes in string values:

A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes (if necessary).

(Number, boolean and null values don’t get enclosed in double quotes, but can’t contain double quotes in the value anyway.)