Hi
Attached patch improves documentation of json_decode():
- document more cases where json_decode()
deviates from rfc7159 by being more permissive.
It's debatable whether some of the permissive cases
should result in errors, but the documentation patch
reflects the current behavior of json_decode().
- removed restriction about empty object members
as this was fixed in 8.0.309.
Regards
Dominique
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 6c3c0da..5ab4816 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -5304,13 +5304,29 @@ json_decode({string}) *json_decode()*
in Vim values. See |json_encode()| for the relation between
JSON and Vim values.
The decoding is permissive:
- - A trailing comma in an array and object is ignored.
+ - A trailing comma in an array and object is ignored, e.g.
+ "[1, 2, ]" for "[1, 2]".
- More floating point numbers are recognized, e.g. "1." for
- "1.0".
- However, a duplicate key in an object is not allowed. *E938*
- The result must be a valid Vim type:
- - An empty object member name is not allowed.
- - Duplicate object member names are not allowed.
+ "1.0", or "001.2" for "1.2". Special floating point values
+ "Infinity" and "NaN" (capitalization ignored) are accepted.
+ - Leading zeroes in integer numbers are ignored, e.g. "012"
+ for "12" or "-012" for "-12".
+ - Capitalization is ignored in literal names null, true or
+ false, e.g. "NULL" for "null", "True" for "true".
+ - Control characters U+0000 through U+001F which are not
+ escaped in strings are accepted, e.g. " " (tab
+ character in string) for "\t".
+ - Backslash in an invalid 2-character sequence escape is
+ ignored, e.g. "\a" is decoded as "a".
+ - A correct surrogate pair in JSON strings should normally be
+ a 12 character sequence such as "\uD834\uDD1E", but
+ json_decode() silently accepts truncated surrogate pairs
+ such as "\uD834" or "\uD834\u"
+ *E938*
+ A duplicate key in an object, valid in rfc7159, is not
+ accepted by json_decode() as the result must be a valid Vim
+ type, e.g. {"a":"b", "a":"c"}
+
json_encode({expr}) *json_encode()*
Encode {expr} as JSON and return this as a string.