MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | OPTIONAL |
| 2 | EXPERIMENTAL |
| 3 | SYNOPSIS |
| 4 | |
| 5 | mixed json_parse(string jsonstring) |
| 6 | |
| 7 | DESCRIPTION |
| 8 | This efun parses the JSON object encoded as string in <jsonstr> into a |
| 9 | suitable LPC type. |
| 10 | |
| 11 | Handles the following JSON types: |
| 12 | <null> -> int (0) |
| 13 | <boolean> -> int (0 or 1) |
| 14 | <int | int64> -> int |
| 15 | <double> -> float |
| 16 | <string> -> string |
| 17 | <object> -> mapping |
| 18 | <array> -> arrays |
| 19 | All other JSON types cause a runtime error. |
| 20 | |
| 21 | The JSON object can nest other JSON objects. |
| 22 | |
| 23 | The function is available only if the driver is compiled with Iksemel |
| 24 | support. In that case, __JSON__ is defined. |
| 25 | |
| 26 | LIMITATIONS |
| 27 | 64 bit wide integers can only be parsed losslessly on hosts with |
| 28 | a 64 bit wide LPC int and json-c library newer than 0.90. |
| 29 | |
| 30 | BUGS |
| 31 | __FLOAT_MIN__ is not serialized/parsed losslessly. |
| 32 | |
| 33 | EXAMPLES |
| 34 | json_parse("42") -> 42 |
| 35 | json_parse("42.0") -> 42.0 |
| 36 | json_parse("\"hello world\\n\"") -> "hello world\n" |
| 37 | json_parse("[ 1, 2, 3, 4, 5, 6 ]") -> ({1,2,3,4,5,6}) |
| 38 | json_parse("{ \"test 2\": 42.000000, \"test 1\": 42 }") |
| 39 | -> ([ "test 1": 42, "test 2": 42.0 ]) |
| 40 | |
| 41 | HISTORY |
| 42 | Added in LDMud 3.5.0 |
| 43 | |
| 44 | SEE ALSO |
| 45 | json_serialize(E) |