A string literal is zero or more Unicode code points enclosed in single or double quotes. Unicode code points may also be represented by an escape sequence. All code points may appear literally in a string literal except for the closing quote code points, U+005C (REVERSE SOLIDUS), U+000D (CARRIAGE RETURN), U+2028 (LINE SEPARATOR), U+2029 (PARAGRAPH SEPARATOR), and U+000A (LINE FEED). Any code points may appear in the form of an escape sequence. String literals evaluate to ECMAScript String values. When generating these String values Unicode code points are UTF-16 encoded as defined in
A conforming implementation, when processing
The definition of the nonterminal
A line terminator code point<LF> and <CR> cannot appear in a string literal, except as part of a cause a line terminator code point to be part ofinclude either in the String value of a string literal is to use an escape sequence such as \n
or \u000A
.
A string literal stands for a value of the String type. The String value (SV) of the literal is described in terms of code unit values contributed by the various parts of the string literal. As part of this process, some Unicode code points within the string literal are interpreted as having a mathematical value (MV), as described below or in
2048 | Escape Sequence 2049 | 2050 | | 2051 |2052 | Code Unit Value 2053 | 2054 | | 2055 |2056 | Unicode Character Name 2057 | 2058 | | 2059 |2060 | Symbol 2061 | 2062 | | 2063 |
---|---|---|---|
2066 | \b
2067 |
2068 | |
2069 |
2070 | 0x0008
2071 |
2072 | |
2073 | 2074 | BACKSPACE 2075 | 2076 | | 2077 |2078 | <BS> 2079 | 2080 | | 2081 |
2084 | \t
2085 |
2086 | |
2087 |
2088 | 0x0009
2089 |
2090 | |
2091 | 2092 | CHARACTER TABULATION 2093 | 2094 | | 2095 |2096 | <HT> 2097 | 2098 | | 2099 |
2102 | \n
2103 |
2104 | |
2105 |
2106 | 0x000A
2107 |
2108 | |
2109 | 2110 | LINE FEED (LF) 2111 | 2112 | | 2113 |2114 | <LF> 2115 | 2116 | | 2117 |
2120 | \v
2121 |
2122 | |
2123 |
2124 | 0x000B
2125 |
2126 | |
2127 | 2128 | LINE TABULATION 2129 | 2130 | | 2131 |2132 | <VT> 2133 | 2134 | | 2135 |
2138 | \f
2139 |
2140 | |
2141 |
2142 | 0x000C
2143 |
2144 | |
2145 | 2146 | FORM FEED (FF) 2147 | 2148 | | 2149 |2150 | <FF> 2151 | 2152 | | 2153 |
2156 | \r
2157 |
2158 | |
2159 |
2160 | 0x000D
2161 |
2162 | |
2163 | 2164 | CARRIAGE RETURN (CR) 2165 | 2166 | | 2167 |2168 | <CR> 2169 | 2170 | | 2171 |
2174 | \"
2175 |
2176 | |
2177 |
2178 | 0x0022
2179 |
2180 | |
2181 | 2182 | QUOTATION MARK 2183 | 2184 | | 2185 |
2186 | "
2187 |
2188 | |
2189 |
2192 | \'
2193 |
2194 | |
2195 |
2196 | 0x0027
2197 |
2198 | |
2199 | 2200 | APOSTROPHE 2201 | 2202 | | 2203 |
2204 | '
2205 |
2206 | |
2207 |
2210 | \\
2211 |
2212 | |
2213 |
2214 | 0x005C
2215 |
2216 | |
2217 | 2218 | REVERSE SOLIDUS 2219 | 2220 | | 2221 |
2222 | \
2223 |
2224 | |
2225 |
The parse
function parses a JSON text (a JSON-formatted String) and produces an ECMAScript value. The JSON format represents literals, arrays, and objects with a syntax similar to the syntax for ECMAScript literals, Array Initializers, and Object Initializers. After parsing, JSON objects are realized as ECMAScript objects. JSON arrays are realized as ECMAScript Array instances. JSON strings, numbers, booleans, and null are realized as ECMAScript Strings, Numbers, Booleans, and
The optional reviver parameter is a function that takes two parameters, key and value. It can filter and transform the results. It is called with each of the key/value pairs produced by the parse, and its return value is used instead of the original value. If it returns what it received, the structure is not modified. If it returns
"("
, JText, and ");"
.The length
property of the parse
function is 2.
JSON allows Unicode code units 0x2028 (LINE SEPARATOR) and 0x2029 (PARAGRAPH SEPARATOR) to directly appear in String literals without using an escape sequence. This is enabled by using the following alternative definition of
Valid JSON text is a subset of the ECMAScript
© 2018 Richard Gibson
2302 | 2303 |All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT http://www.ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.
2305 | 2306 |Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
2307 | 2308 |THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2315 | 2316 |5 | title: Subsume JSON 6 | status: proposal 7 | stage: 4 8 | shortname: <a href="https://github.com/tc39/proposal-json-superset">proposal-json-superset</a> 9 | contributors: Richard Gibson 10 |11 |
A string literal is zero or more Unicode code points enclosed in single or double quotes. Unicode code points may also be represented by an escape sequence. All code points may appear literally in a string literal except for the closing quote code points, U+005C (REVERSE SOLIDUS), U+000D (CARRIAGE RETURN), U+2028 (LINE SEPARATOR), U+2029 (PARAGRAPH SEPARATOR), and U+000A (LINE FEED). Any code points may appear in the form of an escape sequence. String literals evaluate to ECMAScript String values. When generating these String values Unicode code points are UTF-16 encoded as defined in
A conforming implementation, when processing strict mode code, must not extend the syntax of |EscapeSequence| to include
The definition of the nonterminal |HexDigit| is given in
A line terminator code point<LF> and <CR> cannot appear in a string literal, except as part of a |LineContinuation| to produce the empty code points sequence. The proper way to cause a line terminator code point to be part ofinclude either in the String value of a string literal is to use an escape sequence such as `\\n` or `\\u000A`.
A string literal stands for a value of the String type. The String value (SV) of the literal is described in terms of code unit values contributed by the various parts of the string literal. As part of this process, some Unicode code points within the string literal are interpreted as having a mathematical value (MV), as described below or in
197 | Escape Sequence 198 | | 199 |200 | Code Unit Value 201 | | 202 |203 | Unicode Character Name 204 | | 205 |206 | Symbol 207 | | 208 |
---|---|---|---|
211 | `\\b` 212 | | 213 |214 | `0x0008` 215 | | 216 |217 | BACKSPACE 218 | | 219 |220 | <BS> 221 | | 222 |
225 | `\\t` 226 | | 227 |228 | `0x0009` 229 | | 230 |231 | CHARACTER TABULATION 232 | | 233 |234 | <HT> 235 | | 236 |
239 | `\\n` 240 | | 241 |242 | `0x000A` 243 | | 244 |245 | LINE FEED (LF) 246 | | 247 |248 | <LF> 249 | | 250 |
253 | `\\v` 254 | | 255 |256 | `0x000B` 257 | | 258 |259 | LINE TABULATION 260 | | 261 |262 | <VT> 263 | | 264 |
267 | `\\f` 268 | | 269 |270 | `0x000C` 271 | | 272 |273 | FORM FEED (FF) 274 | | 275 |276 | <FF> 277 | | 278 |
281 | `\\r` 282 | | 283 |284 | `0x000D` 285 | | 286 |287 | CARRIAGE RETURN (CR) 288 | | 289 |290 | <CR> 291 | | 292 |
295 | `\\"` 296 | | 297 |298 | `0x0022` 299 | | 300 |301 | QUOTATION MARK 302 | | 303 |304 | `"` 305 | | 306 |
309 | `\\'` 310 | | 311 |312 | `0x0027` 313 | | 314 |315 | APOSTROPHE 316 | | 317 |318 | `'` 319 | | 320 |
323 | `\\\\` 324 | | 325 |326 | `0x005C` 327 | | 328 |329 | REVERSE SOLIDUS 330 | | 331 |332 | `\\` 333 | | 334 |
The `parse` function parses a JSON text (a JSON-formatted String) and produces an ECMAScript value. The JSON format represents literals, arrays, and objects with a syntax similar to the syntax for ECMAScript literals, Array Initializers, and Object Initializers. After parsing, JSON objects are realized as ECMAScript objects. JSON arrays are realized as ECMAScript Array instances. JSON strings, numbers, booleans, and null are realized as ECMAScript Strings, Numbers, Booleans, and *null*.
366 |The optional _reviver_ parameter is a function that takes two parameters, _key_ and _value_. It can filter and transform the results. It is called with each of the _key_/_value_ pairs produced by the parse, and its return value is used instead of the original value. If it returns what it received, the structure is not modified. If it returns *undefined* then the property is deleted from the result.
367 |The `length` property of the `parse` function is 2.
384 |JSON allows Unicode code units 0x2028 (LINE SEPARATOR) and 0x2029 (PARAGRAPH SEPARATOR) to directly appear in String literals without using an escape sequence. This is enabled by using the following alternative definition of |DoubleStringCharacter| when parsing _scriptText_ in step 4:
386 |Valid JSON text is a subset of the ECMAScript |PrimaryExpression| syntax as modified by Step 4 above. Step 2 verifies that _JText_ conforms to that subset, and step 6 verifies that that parsing and evaluation returns a value of an appropriate type.
399 |