mirror of
https://github.com/nlohmann/json
synced 2024-11-10 06:20:06 +00:00
🔨 clean up
This commit is contained in:
parent
e22ce45065
commit
65e8ee985a
@ -1508,7 +1508,7 @@ The library supports **Unicode input** as follows:
|
|||||||
|
|
||||||
### Comments in JSON
|
### Comments in JSON
|
||||||
|
|
||||||
This library does not support comments. It does so for three reasons:
|
This library does not support comments by default. It does so for three reasons:
|
||||||
|
|
||||||
1. Comments are not part of the [JSON specification](https://tools.ietf.org/html/rfc8259). You may argue that `//` or `/* */` are allowed in JavaScript, but JSON is not JavaScript.
|
1. Comments are not part of the [JSON specification](https://tools.ietf.org/html/rfc8259). You may argue that `//` or `/* */` are allowed in JavaScript, but JSON is not JavaScript.
|
||||||
2. This was not an oversight: Douglas Crockford [wrote on this](https://plus.google.com/118095276221607585885/posts/RK8qyGVaGSr) in May 2012:
|
2. This was not an oversight: Douglas Crockford [wrote on this](https://plus.google.com/118095276221607585885/posts/RK8qyGVaGSr) in May 2012:
|
||||||
@ -1519,11 +1519,7 @@ This library does not support comments. It does so for three reasons:
|
|||||||
|
|
||||||
3. It is dangerous for interoperability if some libraries would add comment support while others don't. Please check [The Harmful Consequences of the Robustness Principle](https://tools.ietf.org/html/draft-iab-protocol-maintenance-01) on this.
|
3. It is dangerous for interoperability if some libraries would add comment support while others don't. Please check [The Harmful Consequences of the Robustness Principle](https://tools.ietf.org/html/draft-iab-protocol-maintenance-01) on this.
|
||||||
|
|
||||||
This library will not support comments in the future. If you wish to use comments, I see three options:
|
However, you can pass set parameter `ignore_comments` to true in the `parse` function to ignore `//` or `/* */` comments. Comments will then be treated as whitespace.
|
||||||
|
|
||||||
1. Strip comments before using this library.
|
|
||||||
2. Use a different JSON library with comment support.
|
|
||||||
3. Use a format that natively supports comments (e.g., YAML or JSON5).
|
|
||||||
|
|
||||||
### Order of object keys
|
### Order of object keys
|
||||||
|
|
||||||
|
@ -1489,6 +1489,15 @@ scan_number_done:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void skip_whitespace()
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
get();
|
||||||
|
}
|
||||||
|
while (current == ' ' or current == '\t' or current == '\n' or current == '\r');
|
||||||
|
}
|
||||||
|
|
||||||
token_type scan()
|
token_type scan()
|
||||||
{
|
{
|
||||||
// initially, skip the BOM
|
// initially, skip the BOM
|
||||||
@ -1499,11 +1508,7 @@ scan_number_done:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// read next character and ignore whitespace
|
// read next character and ignore whitespace
|
||||||
do
|
skip_whitespace();
|
||||||
{
|
|
||||||
get();
|
|
||||||
}
|
|
||||||
while (current == ' ' or current == '\t' or current == '\n' or current == '\r');
|
|
||||||
|
|
||||||
// ignore comments
|
// ignore comments
|
||||||
if (ignore_comments and current == '/')
|
if (ignore_comments and current == '/')
|
||||||
@ -1514,11 +1519,7 @@ scan_number_done:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// skip following whitespace
|
// skip following whitespace
|
||||||
do
|
skip_whitespace();
|
||||||
{
|
|
||||||
get();
|
|
||||||
}
|
|
||||||
while (current == ' ' or current == '\t' or current == '\n' or current == '\r');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (current)
|
switch (current)
|
||||||
|
@ -6565,8 +6565,9 @@ class basic_json
|
|||||||
(optional)
|
(optional)
|
||||||
@param[in] allow_exceptions whether to throw exceptions in case of a
|
@param[in] allow_exceptions whether to throw exceptions in case of a
|
||||||
parse error (optional, true by default)
|
parse error (optional, true by default)
|
||||||
@param[in] ignore_comments whether comments should be ignored (true) or
|
@param[in] ignore_comments whether comments should be ignored and treated
|
||||||
yield a parse error (true); (optional, false by default)
|
like whitespace (true) or yield a parse error (true); (optional, false by
|
||||||
|
default)
|
||||||
|
|
||||||
@return deserialized JSON value; in case of a parse error and
|
@return deserialized JSON value; in case of a parse error and
|
||||||
@a allow_exceptions set to `false`, the return value will be
|
@a allow_exceptions set to `false`, the return value will be
|
||||||
@ -6623,8 +6624,9 @@ class basic_json
|
|||||||
(optional)
|
(optional)
|
||||||
@param[in] allow_exceptions whether to throw exceptions in case of a
|
@param[in] allow_exceptions whether to throw exceptions in case of a
|
||||||
parse error (optional, true by default)
|
parse error (optional, true by default)
|
||||||
@param[in] ignore_comments whether comments should be ignored (true) or
|
@param[in] ignore_comments whether comments should be ignored and treated
|
||||||
yield a parse error (true); (optional, false by default)
|
like whitespace (true) or yield a parse error (true); (optional, false by
|
||||||
|
default)
|
||||||
|
|
||||||
@return deserialized JSON value; in case of a parse error and
|
@return deserialized JSON value; in case of a parse error and
|
||||||
@a allow_exceptions set to `false`, the return value will be
|
@a allow_exceptions set to `false`, the return value will be
|
||||||
@ -6676,8 +6678,9 @@ class basic_json
|
|||||||
iterators.
|
iterators.
|
||||||
|
|
||||||
@param[in] i input to read from
|
@param[in] i input to read from
|
||||||
@param[in] ignore_comments whether comments should be ignored (true) or
|
@param[in] ignore_comments whether comments should be ignored and treated
|
||||||
yield a parse error (true); (optional, false by default)
|
like whitespace (true) or yield a parse error (true); (optional, false by
|
||||||
|
default)
|
||||||
|
|
||||||
@return Whether the input read from @a i is valid JSON.
|
@return Whether the input read from @a i is valid JSON.
|
||||||
|
|
||||||
@ -6728,9 +6731,9 @@ class basic_json
|
|||||||
@param[in,out] sax SAX event listener
|
@param[in,out] sax SAX event listener
|
||||||
@param[in] format the format to parse (JSON, CBOR, MessagePack, or UBJSON)
|
@param[in] format the format to parse (JSON, CBOR, MessagePack, or UBJSON)
|
||||||
@param[in] strict whether the input has to be consumed completely
|
@param[in] strict whether the input has to be consumed completely
|
||||||
@param[in] ignore_comments whether comments should be ignored (true) or
|
@param[in] ignore_comments whether comments should be ignored and treated
|
||||||
yield a parse error (true); (optional, false by default); only applieds to
|
like whitespace (true) or yield a parse error (true); (optional, false by
|
||||||
the JSON file format.
|
default); only applies to the JSON file format.
|
||||||
|
|
||||||
@return return value of the last processed SAX event
|
@return return value of the last processed SAX event
|
||||||
|
|
||||||
|
@ -9556,6 +9556,15 @@ scan_number_done:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void skip_whitespace()
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
get();
|
||||||
|
}
|
||||||
|
while (current == ' ' or current == '\t' or current == '\n' or current == '\r');
|
||||||
|
}
|
||||||
|
|
||||||
token_type scan()
|
token_type scan()
|
||||||
{
|
{
|
||||||
// initially, skip the BOM
|
// initially, skip the BOM
|
||||||
@ -9566,11 +9575,7 @@ scan_number_done:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// read next character and ignore whitespace
|
// read next character and ignore whitespace
|
||||||
do
|
skip_whitespace();
|
||||||
{
|
|
||||||
get();
|
|
||||||
}
|
|
||||||
while (current == ' ' or current == '\t' or current == '\n' or current == '\r');
|
|
||||||
|
|
||||||
// ignore comments
|
// ignore comments
|
||||||
if (ignore_comments and current == '/')
|
if (ignore_comments and current == '/')
|
||||||
@ -9581,11 +9586,7 @@ scan_number_done:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// skip following whitespace
|
// skip following whitespace
|
||||||
do
|
skip_whitespace();
|
||||||
{
|
|
||||||
get();
|
|
||||||
}
|
|
||||||
while (current == ' ' or current == '\t' or current == '\n' or current == '\r');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (current)
|
switch (current)
|
||||||
@ -22451,8 +22452,9 @@ class basic_json
|
|||||||
(optional)
|
(optional)
|
||||||
@param[in] allow_exceptions whether to throw exceptions in case of a
|
@param[in] allow_exceptions whether to throw exceptions in case of a
|
||||||
parse error (optional, true by default)
|
parse error (optional, true by default)
|
||||||
@param[in] ignore_comments whether comments should be ignored (true) or
|
@param[in] ignore_comments whether comments should be ignored and treated
|
||||||
yield a parse error (true); (optional, false by default)
|
like whitespace (true) or yield a parse error (true); (optional, false by
|
||||||
|
default)
|
||||||
|
|
||||||
@return deserialized JSON value; in case of a parse error and
|
@return deserialized JSON value; in case of a parse error and
|
||||||
@a allow_exceptions set to `false`, the return value will be
|
@a allow_exceptions set to `false`, the return value will be
|
||||||
@ -22509,8 +22511,9 @@ class basic_json
|
|||||||
(optional)
|
(optional)
|
||||||
@param[in] allow_exceptions whether to throw exceptions in case of a
|
@param[in] allow_exceptions whether to throw exceptions in case of a
|
||||||
parse error (optional, true by default)
|
parse error (optional, true by default)
|
||||||
@param[in] ignore_comments whether comments should be ignored (true) or
|
@param[in] ignore_comments whether comments should be ignored and treated
|
||||||
yield a parse error (true); (optional, false by default)
|
like whitespace (true) or yield a parse error (true); (optional, false by
|
||||||
|
default)
|
||||||
|
|
||||||
@return deserialized JSON value; in case of a parse error and
|
@return deserialized JSON value; in case of a parse error and
|
||||||
@a allow_exceptions set to `false`, the return value will be
|
@a allow_exceptions set to `false`, the return value will be
|
||||||
@ -22562,8 +22565,9 @@ class basic_json
|
|||||||
iterators.
|
iterators.
|
||||||
|
|
||||||
@param[in] i input to read from
|
@param[in] i input to read from
|
||||||
@param[in] ignore_comments whether comments should be ignored (true) or
|
@param[in] ignore_comments whether comments should be ignored and treated
|
||||||
yield a parse error (true); (optional, false by default)
|
like whitespace (true) or yield a parse error (true); (optional, false by
|
||||||
|
default)
|
||||||
|
|
||||||
@return Whether the input read from @a i is valid JSON.
|
@return Whether the input read from @a i is valid JSON.
|
||||||
|
|
||||||
@ -22614,9 +22618,9 @@ class basic_json
|
|||||||
@param[in,out] sax SAX event listener
|
@param[in,out] sax SAX event listener
|
||||||
@param[in] format the format to parse (JSON, CBOR, MessagePack, or UBJSON)
|
@param[in] format the format to parse (JSON, CBOR, MessagePack, or UBJSON)
|
||||||
@param[in] strict whether the input has to be consumed completely
|
@param[in] strict whether the input has to be consumed completely
|
||||||
@param[in] ignore_comments whether comments should be ignored (true) or
|
@param[in] ignore_comments whether comments should be ignored and treated
|
||||||
yield a parse error (true); (optional, false by default); only applieds to
|
like whitespace (true) or yield a parse error (true); (optional, false by
|
||||||
the JSON file format.
|
default); only applies to the JSON file format.
|
||||||
|
|
||||||
@return return value of the last processed SAX event
|
@return return value of the last processed SAX event
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user