1
- # Jason
1
+ # JasonVendored
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
- Jason is usually only twice as slow.
8
+ JasonVendored 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 )> Jason .encode! (%{" age" => 44 , " name" => " Steve Irwin" , " nationality" => " Australian" })
29
+ iex (1 )> JasonVendored .encode! (%{" age" => 44 , " name" => " Steve Irwin" , " nationality" => " Australian" })
30
30
" {\" age\" :44,\" name\" :\" Steve Irwin\" ,\" nationality\" :\" Australian\" }"
31
31
32
- iex (2 )> Jason .decode! (~s( {"age":44,"name":"Steve Irwin","nationality":"Australian"}) )
32
+ iex (2 )> JasonVendored .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 ` Jason ` by default. For earlier versions, please refer to
42
+ Versions starting at 0.14.0 use ` JasonVendored ` 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 ` Jason ` by default. For earlier versions, please refer to
47
+ Versions starting at 3.0.0 use ` JasonVendored ` 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 ` Jason ` by default. For earlier versions, please refer to
52
+ Phoenix starting at 1.4.0 uses ` JasonVendored ` 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: Jason
63
+ json_codec: JasonVendored
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: Jason ]
68
+ init_opts: [schema: MyApp .Schema , json_codec: JasonVendored ]
69
69
```
70
70
71
71
## Benchmarks
@@ -85,24 +85,24 @@ A HTML report of the benchmarks (after their execution) can be found in
85
85
86
86
## Differences to Poison
87
87
88
- Jason has a couple feature differences compared to Poison.
88
+ JasonVendored has a couple feature differences compared to Poison.
89
89
90
- * Jason follows the JSON spec more strictly, for example it does not allow
90
+ * JasonVendored 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 ` Jason .Encoder` protocol is always required.
96
+ of the ` JasonVendored .Encoder` protocol is always required.
97
97
* different pretty-printing customisation options (default ` pretty: true ` works the same)
98
98
99
99
If you require encoders for any of the unsupported collection types, I suggest
100
100
adding the needed implementations directly to your project:
101
101
102
102
``` elixir
103
- defimpl Jason .Encoder , for: [MapSet , Range , Stream ] do
103
+ defimpl JasonVendored .Encoder , for: [MapSet , Range , Stream ] do
104
104
def encode (struct, opts) do
105
- Jason .Encode .list (Enum .to_list (struct), opts)
105
+ JasonVendored .Encode .list (Enum .to_list (struct), opts)
106
106
end
107
107
end
108
108
```
@@ -112,7 +112,7 @@ if you own the struct, you can derive the implementation specifying
112
112
which fields should be encoded to JSON:
113
113
114
114
``` elixir
115
- @derive {Jason .Encoder , only: [.... ]}
115
+ @derive {JasonVendored .Encoder , only: [.... ]}
116
116
defstruct # ...
117
117
```
118
118
@@ -121,21 +121,21 @@ used carefully to avoid accidentally leaking private information
121
121
when new fields are added:
122
122
123
123
``` elixir
124
- @derive Jason .Encoder
124
+ @derive JasonVendored .Encoder
125
125
defstruct # ...
126
126
```
127
127
128
128
Finally, if you don't own the struct you want to encode to JSON,
129
129
you may use ` Protocol.derive/3 ` placed outside of any module:
130
130
131
131
``` elixir
132
- Protocol .derive (Jason .Encoder , NameOfTheStruct , only: [.. .])
133
- Protocol .derive (Jason .Encoder , NameOfTheStruct )
132
+ Protocol .derive (JasonVendored .Encoder , NameOfTheStruct , only: [.. .])
133
+ Protocol .derive (JasonVendored .Encoder , NameOfTheStruct )
134
134
```
135
135
136
136
## License
137
137
138
- Jason is released under the Apache License 2.0 - see the [ LICENSE] ( LICENSE ) file.
138
+ JasonVendored is released under the Apache License 2.0 - see the [ LICENSE] ( LICENSE ) file.
139
139
140
140
Some elements of tests and benchmarks have their origins in the
141
141
[ 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