-
Notifications
You must be signed in to change notification settings - Fork 64
/
JSON.txt
86 lines (71 loc) · 3.13 KB
/
JSON.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
*vital/Web/JSON.txt* JSON parser written in pure Vim script.
Maintainer: mattn <[email protected]>
lambdalisue <[email protected]>
==============================================================================
CONTENTS *Vital.Web.JSON-contents*
INTRODUCTION |Vital.Web.JSON-introduction|
INTERFACE |Vital.Web.JSON-interface|
Consts |Vital.Web.JSON-consts|
Functions |Vital.Web.JSON-functions|
==============================================================================
INTRODUCTION *Vital.Web.JSON-introduction*
*Vital.Web.JSON* is JSON parser Library.
==============================================================================
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.
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.
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.
------------------------------------------------------------------------------
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]'
<
{settings} is a |Dictionary| which allows the following:
'indent'
The number of spaces used as an indentation. When the value is greater
than 0, the encoded JSON will be formatted with the specified indent
level. The default value is 0.
>
echo s:JSON.encode({'a': 0, 'b': 1})
" => '{"a":0,"b":1}'
echo s:JSON.encode({'a': 0, 'b': 1}, {'indent': 2})
" => '{
" "a": 0,
" "b": 1
" }'
<
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.
>
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]
<
=============================================================================
vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl