@@ -5,7 +5,17 @@ Works with binaries as strings, arrays as lists and only knows how to decode UTF
5
5
JSONX IS VERY FAST!
6
6
------------------
7
7
8
- Check out a benchmark [ si14/erl_json_test] ( https://github.com/si14/erl_json_test ) and record encoding tests in ` /benchmarks/test_encode_records.erl `
8
+ Check out a benchmark [ si14/erl_json_test] ( https://github.com/si14/erl_json_test ) or
9
+ [ davisp/erljson_bench] ( https://github.com/davisp/erljson_bench ) and
10
+ record encoding tests in ` /benchmarks/test_encode_records.erl `
11
+
12
+ INSTALLATION and DOCUMENTATION
13
+ ------------------------------
14
+
15
+ * cd jsonx
16
+ * make
17
+ * make doc
18
+ * firefox doc/index.html&
9
19
10
20
JSONX can encode and decode Erlang records!
11
21
-------------------------------------------
@@ -86,46 +96,10 @@ nonstrict_decoder1() ->
86
96
```
87
97
88
98
89
- Decode (JSON -> Erlang)
90
- ----------------------
91
-
92
- null :-> null
93
- true :-> true
94
- false :-> false
95
- "string" :-> <<"binary">>
96
- [1, 2.3, []] :-> [1, 2.3, []]
97
- {"this": "json"} :-> {[{<<"this">>: <<"json">>}]} %% default eep18
98
- {"this": "json"} :-> [{<<"this">>: <<"json">>}] %% optional proplist
99
- {"this": "json"} :-> {struct, [{<<"this">>: <<"json">>}]} %% optional struct
100
- JSONObject :-> #rec{...} %% decoder must be predefined
101
-
102
- Encode (Erlang -> JSON)
103
- -----------------------
104
-
105
- null :-> null
106
- true :-> true
107
- false :-> false
108
- atom :-> "atom"
109
- <<"str">> :-> "str"
110
- [1, 2.99] :-> [1, 2.99]
111
- {struct, [{<<"this">>: <<"json">>}]} :-> {"this": "json"}
112
- [{<<"this">>: <<"json">>}] :-> {"this": "json"}
113
- {[{<<"this">>: <<"json">>}]} :-> {"this": "json"}
114
- {json, IOList} :-> `iolist_to_binary(IOList)` %% include with no validation
115
- #rec{...} :-> JSONObject %% encoder must be predefined
116
-
117
- INSTALLATION and DOCUMENTATION
118
- ------------------------------
119
-
120
- * cd jsonx
121
- * make
122
- * make doc
123
- * firefox doc/index.html&
124
-
125
99
Examples encoding JSON
126
100
----------------------
127
101
128
- ~~~~~
102
+ ``` erlang
129
103
1 > jsonx :encode ([1 , 2.3 , true , false , null , atom , <<" string" >>, []]).
130
104
<<" [1,2.3,true,false,null,\" atom\" ,\" string\" ,[]]" >>
131
105
@@ -140,12 +114,12 @@ Examples encoding JSON
140
114
% % Object as eep18 propsal
141
115
4 > jsonx :encode ( {[{name , <<" Ivan" >>}, {age , 33 }, {phones , [3332211 , 4443322 ]}]} ).
142
116
<<" {\" name\" :\" Ivan\" ,\" age\" :33,\" phones\" :[3332211,4443322]}" >>
143
- ~~~~~
117
+ ```
144
118
145
119
Examples decoding JSON
146
120
----------------------
147
121
148
- ~~~~~
122
+ ``` erlang
149
123
1 > jsonx :decode (<<" {\" name\" :\" Ivan\" ,\" age\" :33,\" phones\" :[3332211,4443322]}" >>).
150
124
{[{<<" name" >>,<<" Ivan" >>},
151
125
{<<" age" >>,33 },
@@ -165,4 +139,32 @@ Examples decoding JSON
165
139
{struct ,[{<<" name" >>,<<" Ivan" >>},
166
140
{<<" age" >>,33 },
167
141
{<<" phones" >>,[3332211 ,4443322 ]}]}
168
- ~~~~~
142
+ ```
143
+
144
+ Mapping (JSON -> Erlang)
145
+ ----------------------
146
+
147
+ null :-> null
148
+ true :-> true
149
+ false :-> false
150
+ "string" :-> <<"binary">>
151
+ [1, 2.3, []] :-> [1, 2.3, []]
152
+ {"this": "json"} :-> {[{<<"this">>: <<"json">>}]} %% default eep18
153
+ {"this": "json"} :-> [{<<"this">>: <<"json">>}] %% optional proplist
154
+ {"this": "json"} :-> {struct, [{<<"this">>: <<"json">>}]} %% optional struct
155
+ JSONObject :-> #rec{...} %% decoder must be predefined
156
+
157
+ Mapping (Erlang -> JSON)
158
+ -----------------------
159
+
160
+ null :-> null
161
+ true :-> true
162
+ false :-> false
163
+ atom :-> "atom"
164
+ <<"str">> :-> "str"
165
+ [1, 2.99] :-> [1, 2.99]
166
+ {struct, [{<<"this">>: <<"json">>}]} :-> {"this": "json"}
167
+ [{<<"this">>: <<"json">>}] :-> {"this": "json"}
168
+ {[{<<"this">>: <<"json">>}]} :-> {"this": "json"}
169
+ {json, IOList} :-> `iolist_to_binary(IOList)` %% include with no validation
170
+ #rec{...} :-> JSONObject %% encoder must be predefined
0 commit comments