Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do curly braces inside json string objects need to be escaped?

This string is part a JSON object/file:

"Mask" : "{0}(CASE WHEN {1} = {2} THEN {3} ELSE 0 END) {4}" 

Will JSON recognize that as part of standard JSON notation or do I need to escape those curly braces s somehow?

If so, how does one escape curly braces in JSON?

like image 389
A.G. Avatar asked Nov 09 '13 16:11

A.G.


People also ask

What should be escaped in JSON string?

In JSON the only characters you must escape are \, ", and control codes. Thus in order to escape your structure, you'll need a JSON specific function. As you might know, all of the escapes can be written as \uXXXX where XXXX is the UTF-16 code unit¹ for that character.

How do you pass curly braces in JSON?

Google Sheets as JSON data source for JavaScriptCurly braces hold objects and each name is followed by ':'(colon), the name/value pairs are separated by , (comma). Square brackets hold arrays and values are separated by ,(comma).

Does JSON always start with curly braces?

From what I can read on json.org, all JSON strings should start with { (curly brace), and [ characters (square brackets) represent an array element in JSON.

Are brackets allowed in JSON?

JSON (JavaScript Object Notation) This makes JSON human-readable. JSON is easier to parse than XML. This is because JSON uses a fixed set of delimiters. These delimiters include curly braces ({ }), commas (,), colons (:) and square brackets ([]).


2 Answers

No. Curly braces do not have to be escaped in JSON.

like image 150
Karthik Avatar answered Sep 24 '22 07:09

Karthik


No, curly braces do not have to be escaped in JSON strings.

JSON is defined in RFC 7159. The Section 7: Strings lists the string characters that must be escaped:

All Unicode characters may be placed within the quotation marks, except for the characters that must be escaped: quotation mark, reverse solidus, and the control characters (U+0000 through U+001F).

While all characters can be escaped, curly braces do not have to be.

like image 27
Maxim Avatar answered Sep 23 '22 07:09

Maxim