forked from nkronlage/JavaScripture
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson.jsdoc
More file actions
100 lines (75 loc) · 2.62 KB
/
json.jsdoc
File metadata and controls
100 lines (75 loc) · 2.62 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
JSON : Object
Contains methods for encoding and decoding JSON strings.
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.12
----
parse(str : String) : Object
Parses the specified string of JSON and converts it to an **Object**.
<example>
var x = JSON.parse('{"foo": 1, "bar": 2}');
console.log(x.foo);
console.log(x.bar);
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.12.2
----
parse(str : String, reviver(key : String, value : String) : Object) : Object
Parses the specified string of JSON and converts it to an **Object**.
**reviver** will be called for each parsed key/value pair
and the function's return value is used in place of the value.
<example>
var reviver = function(key, value) {
console.log('reviver called with key="' + key + '", value=' + value);
if (key === 'foo') {
return value * 10;
}
return value;
};
var x = JSON.parse('{"foo": 1, "bar": 2}', reviver);
console.log(x.foo);
console.log(x.bar);
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.12.2
----
stringify(value : Object) : String
Converts **value** to a JSON string. If **value** has a **toJSON()** method
on it, the return value of that method will be used.
<example>
var x = { foo: 1, bar: 2 };
console.log(JSON.stringify(x));
x.toJSON = function() {
return { baz: 3 };
};
console.log(JSON.stringify(x));
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.12.3
----
stringify(value : Object, replacer(key : String, value : Object) : String, [indent : String]) : String
Converts **value** to a JSON string. The **replacer** function is called
for each key/value pair and the return value is used as the value in
the final string. If **indent** is specified, each key/value pair will
be on a new line with the **indent** string before the key.
<example>
var x = { foo: 1, bar: 2 };
var replacer = function(key, value) {
console.log('replacer called with key="' + key + '", value=' + value);
if (key === 'foo') return value * 10;
return value;
}
console.log(JSON.stringify(x, replacer, ' '));
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.12.3
----
stringify(value : Object, keyNames : Array<String>, [indent : String]) : String
Converts **value** to a JSON string. If **keyNames** is not **null**, only key/value pairs where the key is in **keyNames**
will be in the JSON string. If **indent** is specified, each key/value pair will
be on a new line with the **indent** string before the key.
<example>
var x = { foo: 1, bar: 2 };
console.log(JSON.stringify(x, ['foo']));
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.12.3