-
Notifications
You must be signed in to change notification settings - Fork 64
WIP: Web.JSON improve to v8 #695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
e8e3ef2
80e1bbe
34afccc
1cf2235
416240d
04349a9
3044278
c661d01
f8de29b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,34 +23,39 @@ INTERFACE *Vital.Web.JSON-interface* | |
CONSTS *Vital.Web.JSON-consts* | ||
|
||
true *Vital.Web.JSON.true* | ||
It is used to indicate 'true' in JSON string. It is represented as a | ||
|Funcref| thus if you assign the value to a variable which name does not | ||
start with a capital, "s:", "w:", "t:" or "b:" will raise an exception. | ||
This returns 1 when you use it as a function. | ||
It is |v:true|. This is left for backward compatibility. | ||
|
||
false *Vital.Web.JSON.false* | ||
It is used to indicate 'false' in JSON string. It is represented as a | ||
|Funcref| thus if you assign the value to a variable which name does not | ||
start with a capital, "s:", "w:", "t:" or "b:" will raise an exception. | ||
This returns 0 when you use it as a function. | ||
It is |v:false|. This is left for backward compatibility. | ||
|
||
null *Vital.Web.JSON.null* | ||
It is used to indicate 'null' in JSON string. It is represented as a | ||
|Funcref| thus if you assign the value to a variable which name does not | ||
start with a capital, "s:", "w:", "t:" or "b:" will raise an exception. | ||
This returns 0 when you use it as a function. | ||
It is |v:null|. This is left for backward compatibility. | ||
|
||
------------------------------------------------------------------------------ | ||
FUNCTIONS *Vital.Web.JSON-functions* | ||
|
||
encode({object}[, {settings}]) *Vital.Web.JSON.encode()* | ||
Encode an object into a JSON string. Special tokens | ||
(e.g. |Vital.Web.JSON.true|) are encoded into corresponding javascript | ||
tokens (e.g. 'true'). | ||
> | ||
echo s:JSON.encode([s:JSON.true, s:JSON.false, s:JSON.null]) | ||
" => '[true, false, null]' | ||
< | ||
Encode an object into a JSON string. | ||
Vim values are converted as follows: | ||
|Number| decimal number | ||
|Float| floating point number | ||
Float nan "NaN" | ||
Float inf "Infinity" | ||
Float -inf "-Infinity" | ||
|String| in double quotes (possibly null) | ||
|List| as an array (possibly null); when | ||
used recursively: [] | ||
|Dict| as an object (possibly null); when | ||
used recursively: {} | ||
|Blob| as an array of the individual bytes | ||
v:false "false" | ||
v:true "true" | ||
v:none "null" | ||
v:null "null" | ||
|Funcref| not possible, error | ||
|job| not possible, error | ||
|channel| not possible, error | ||
|
||
{settings} is a |Dictionary| which allows the following: | ||
|
||
'indent' | ||
|
@@ -65,21 +70,45 @@ encode({object}[, {settings}]) *Vital.Web.JSON.encode()* | |
" "a": 0, | ||
" "b": 1 | ||
" }' | ||
< | ||
'allow_nan' | ||
If 'allows_nan' is 0, it will raise an exception when serializing | ||
out of range float values (nan, inf, -inf). | ||
Otherwise 'NaN', 'Infinity' or '-Infinity' are used to represent these. | ||
The default value is 1. | ||
Note that NaN and Infinity are not the JSON standard. | ||
> | ||
echo s:JSON.encode([0.0/0, 1.0/0, -1.0/0]) | ||
" => [NaN,Infinity,-Infinity] | ||
echo s:JSON.encode([0.0/0], {'allow_nan': 0}) | ||
" => vital: Web.JSON: Invalid float value: nan | ||
< | ||
'ensure_ascii' | ||
If 'ensure_ascii' is 0, all characters without control-chars | ||
(0x01-0x1f) will be output as-is. | ||
Otherwise the output is guaranteed to have all incoming non-ASCII | ||
characters escaped. | ||
The default value is 0. | ||
> | ||
echo s:JSON.encode(["foo", "bár", "\n"]) | ||
" => '["foo","bár","\n"]' | ||
echo s:JSON.encode(["foo", "bár", "\n"], {'ensure_ascii': 1}) | ||
" => '["foo","b\u00e1r","\n"]' | ||
< | ||
decode({json}[, {settings}]) *Vital.Web.JSON.decode()* | ||
Decode a JSON string into an object that vim can treat. | ||
{settings} is a |Dictionary| which allows the following: | ||
|
||
'use_token' | ||
Use special tokens (e.g. |Vital.Web.JSON.true|) to represent | ||
corresponding javascript tokens (e.g. 'true'). | ||
Otherwise 1 or 0 are used to represent these. | ||
The default value is 0. | ||
'allow_nan' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This point is incompatible changing. need appending item to Please There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the point you say Add 'allow_nan' or Remove 'use_token'? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I think, Adding phrase to |
||
If 'allows_nan' is 0, it will raise an exception when deserializing | ||
float constants ('NaN', 'Infinity', '-Infinity'). | ||
Otherwise nan, inf or -inf are used to represent these. | ||
The default value is 1. | ||
> | ||
echo s:JSON.decode('[true, false, null]') | ||
" => [1, 0, 0] | ||
echo s:JSON.decode('[true, false, null]', {'use_token': 1}) | ||
" => [s:JSON.true, s:JSON.false, s:JSON.null] | ||
echo s:JSON.decode('[NaN, Infinity, -Infinity]') | ||
" => [nan, inf, -inf] | ||
echo s:JSON.decode('[NaN]', {'allow_nan': 0}) | ||
" => E121: Undefined variable: NaN | ||
< | ||
|
||
============================================================================= | ||
|
Uh oh!
There was an error while loading. Please reload this page.