Pure Gleam JSON library
- Gleam 100%
| LICENSES | init | |
| src | more get examples | |
| test | more get examples | |
| .gitignore | init | |
| gleam.toml | don't include gleam_json as release dep | |
| manifest.toml | deps update | |
| README.md | fix readme example | |
| REUSE.toml | init | |
josh
Package Version Hex Docs License MIT
Pure Gleam JSON Library
gleam add josh
importjoshimportgleam/dictpubfnmain()->Nil{assertjosh.parse("{\"Hello\": \"World!\"}")==Ok(josh.Object(dict.from_list(#("Hello",josh.String("World!")))))assertjosh.to_string(josh.Array([josh.String("Foo"),josh.String("bar")]))=="[\"foo\",\"bar\"]"}Further documentation can be found at https://hexdocs.pm/josh.
Comparison with gleam_json
Most uses cases should use gleam_json, as it will
be much faster. The only case were this library is preferred is when one would like to
parse the JSON itself into a Gleam type, instead of just its contents.
Tips
Converting to gleam_json
importgleam/dictimportgleam/jsonimportgleam/listimportjoshfnjosh_to_gleam_json(json:josh.Json)->json.Json{casejson{josh.Null->json.null()josh.Bool(bool)->json.bool(bool)josh.Integer(int)->json.int(int)josh.Float(float)->json.float(float)josh.String(string)->json.string(string)josh.Array(array)->json.array(array,josh_to_gleam_json)josh.Object(object)->object|>dict.to_list|>list.map(fn(item){#(item.0,josh_to_json(item.1))})|>json.object}}Development
gleam test # Run the tests
Licensing
This project follows the REUSE 3.3 spec.
All gleam files and gleam.toml are licensed under MIT.