blob: fd68deb3044419798680335b684c5ff3d0cc9f57 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001OPTIONAL
2EXPERIMENTAL
3SYNOPSIS
4
5 string json_serialize(mixed <data>)
6
7DESCRIPTION
8 This efun creates a JSON object from the given LPC variable and
9 returns the object encoded as a LPC string. For container types like
10 arrays, mappings and structs, this will be done recursively.
11
12 Only the following LPC types are serialized. All other LPC types cause
13 a runtime error.
14 <int> -> JSON int
15 <float> -> JSON double
16 <string> -> JSON string
17 <mapping> -> JSON objects
18 <array> -> JSON arrays
19 <struct> -> JSON objects
20
21 The function is available only if the driver is compiled with Iksemel
22 support. In that case, __JSON__ is defined.
23
24LIMITATIONS
25 Only mappings with a width of 1 value per key and only string keys
26 can be serialized.
27 64 bit wide integers can only be serialized losslessly on hosts with
28 a 64 bit wide LPC int and json-c library newer than 0.90.
29
30BUGS
31 __FLOAT_MIN__ is not serialized/parsed losslessly.
32
33EXAMPLES
34 json_serialize(42) -> "42"
35 json_serialize(42.0) -> "42.0"
36 json_serialize("hello world\n") -> "\"hello world\\n\""
37 json_serialize(({1,2,3,4,5,6})) -> "[ 1, 2, 3, 4, 5, 6 ]"
38 json_serialize(([ "test 1": 42, "test 2": 42.0 ]))
39 -> "{ \"test 2\": 42.000000, \"test 1\": 42 }"
40
41HISTORY
42 Added in LDMud 3.5.0
43
44SEE ALSO
45 json_parse(E)