1
- # JasonVendored
1
+ # JasonV
2
2
3
3
A blazing fast JSON parser and generator in pure Elixir.
4
4
5
5
The parser and generator are at least twice as fast as other Elixir/Erlang libraries
6
6
(most notably ` Poison ` ).
7
7
The performance is comparable to ` jiffy ` , which is implemented in C as a NIF.
8
- JasonVendored is usually only twice as slow.
8
+ JasonV is usually only twice as slow.
9
9
10
10
Both parser and generator fully conform to
11
11
[ RFC 8259] ( https://tools.ietf.org/html/rfc8259 ) and
26
26
## Basic Usage
27
27
28
28
``` elixir
29
- iex (1 )> JasonVendored .encode! (%{" age" => 44 , " name" => " Steve Irwin" , " nationality" => " Australian" })
29
+ iex (1 )> JasonV .encode! (%{" age" => 44 , " name" => " Steve Irwin" , " nationality" => " Australian" })
30
30
" {\" age\" :44,\" name\" :\" Steve Irwin\" ,\" nationality\" :\" Australian\" }"
31
31
32
- iex (2 )> JasonVendored .decode! (~s( {"age":44,"name":"Steve Irwin","nationality":"Australian"}) )
32
+ iex (2 )> JasonV .decode! (~s( {"age":44,"name":"Steve Irwin","nationality":"Australian"}) )
33
33
%{" age" => 44 , " name" => " Steve Irwin" , " nationality" => " Australian" }
34
34
```
35
35
@@ -39,17 +39,17 @@ Full documentation can be found at [https://hexdocs.pm/jason](https://hexdocs.pm
39
39
40
40
### Postgrex
41
41
42
- Versions starting at 0.14.0 use ` JasonVendored ` by default. For earlier versions, please refer to
42
+ Versions starting at 0.14.0 use ` JasonV ` by default. For earlier versions, please refer to
43
43
[ previous versions of this document] ( https://github.com/michalmuskala/jason/tree/v1.1.2#postgrex ) .
44
44
45
45
### Ecto
46
46
47
- Versions starting at 3.0.0 use ` JasonVendored ` by default. For earlier versions, please refer to
47
+ Versions starting at 3.0.0 use ` JasonV ` by default. For earlier versions, please refer to
48
48
[ previous versions of this document] ( https://github.com/michalmuskala/jason/tree/v1.1.2#ecto ) .
49
49
50
50
### Plug (and Phoenix)
51
51
52
- Phoenix starting at 1.4.0 uses ` JasonVendored ` by default. For earlier versions, please refer to
52
+ Phoenix starting at 1.4.0 uses ` JasonV ` by default. For earlier versions, please refer to
53
53
[ previous versions of this document] ( https://github.com/michalmuskala/jason/tree/v1.1.2#plug-and-phoenix ) .
54
54
55
55
### Absinthe
@@ -60,12 +60,12 @@ You need to pass the `:json_codec` option to `Absinthe.Plug`
60
60
# When called directly:
61
61
plug Absinthe .Plug ,
62
62
schema: MyApp .Schema ,
63
- json_codec: JasonVendored
63
+ json_codec: JasonV
64
64
65
65
# When used in phoenix router:
66
66
forward " /api" ,
67
67
to: Absinthe .Plug ,
68
- init_opts: [schema: MyApp .Schema , json_codec: JasonVendored ]
68
+ init_opts: [schema: MyApp .Schema , json_codec: JasonV ]
69
69
```
70
70
71
71
## Benchmarks
@@ -85,15 +85,15 @@ A HTML report of the benchmarks (after their execution) can be found in
85
85
86
86
## Differences to Poison
87
87
88
- JasonVendored has a couple feature differences compared to Poison.
88
+ JasonV has a couple feature differences compared to Poison.
89
89
90
- * JasonVendored follows the JSON spec more strictly, for example it does not allow
90
+ * JasonV follows the JSON spec more strictly, for example it does not allow
91
91
unescaped newline characters in JSON strings - e.g. ` "\"\n\"" ` will
92
92
produce a decoding error.
93
93
* no support for decoding into data structures (the ` as: ` option).
94
94
* no built-in encoders for ` MapSet ` , ` Range ` and ` Stream ` .
95
95
* no support for encoding arbitrary structs - explicit implementation
96
- of the ` JasonVendored .Encoder` protocol is always required.
96
+ of the ` JasonV .Encoder` protocol is always required.
97
97
* different pretty-printing customisation options (default ` pretty: true ` works the same)
98
98
99
99
### Encoders
@@ -102,9 +102,9 @@ If you require encoders for any of the unsupported collection types, I suggest
102
102
adding the needed implementations directly to your project:
103
103
104
104
``` elixir
105
- defimpl JasonVendored .Encoder , for: [MapSet , Range , Stream ] do
105
+ defimpl JasonV .Encoder , for: [MapSet , Range , Stream ] do
106
106
def encode (struct, opts) do
107
- JasonVendored .Encode .list (Enum .to_list (struct), opts)
107
+ JasonV .Encode .list (Enum .to_list (struct), opts)
108
108
end
109
109
end
110
110
```
@@ -114,7 +114,7 @@ if you own the struct, you can derive the implementation specifying
114
114
which fields should be encoded to JSON:
115
115
116
116
``` elixir
117
- @derive {JasonVendored .Encoder , only: [.... ]}
117
+ @derive {JasonV .Encoder , only: [.... ]}
118
118
defstruct # ...
119
119
```
120
120
@@ -123,16 +123,16 @@ used carefully to avoid accidentally leaking private information
123
123
when new fields are added:
124
124
125
125
``` elixir
126
- @derive JasonVendored .Encoder
126
+ @derive JasonV .Encoder
127
127
defstruct # ...
128
128
```
129
129
130
130
Finally, if you don't own the struct you want to encode to JSON,
131
131
you may use ` Protocol.derive/3 ` placed outside of any module:
132
132
133
133
``` elixir
134
- Protocol .derive (JasonVendored .Encoder , NameOfTheStruct , only: [.. .])
135
- Protocol .derive (JasonVendored .Encoder , NameOfTheStruct )
134
+ Protocol .derive (JasonV .Encoder , NameOfTheStruct , only: [.. .])
135
+ Protocol .derive (JasonV .Encoder , NameOfTheStruct )
136
136
```
137
137
138
138
## Injecting an already encoded JSON inside a to-be-encoded structure
@@ -151,7 +151,7 @@ or if it is already provided by another system (e.g. `jsonb_agg` with Postgres).
151
151
152
152
## License
153
153
154
- JasonVendored is released under the Apache License 2.0 - see the [ LICENSE] ( LICENSE ) file.
154
+ JasonV is released under the Apache License 2.0 - see the [ LICENSE] ( LICENSE ) file.
155
155
156
156
Some elements of tests and benchmarks have their origins in the
157
157
[ Poison library] ( https://github.com/devinus/poison ) and were initially licensed under [ CC0-1.0] ( https://creativecommons.org/publicdomain/zero/1.0/ ) .
0 commit comments