https://github.com/centralnicgroup-opensource/venom
An Elixir JSON encoder that wraps around poison, allowing round tripping of Elixir data types.
https://github.com/centralnicgroup-opensource/venom
Last synced: 4 months ago
JSON representation
An Elixir JSON encoder that wraps around poison, allowing round tripping of Elixir data types.
- Host: GitHub
- URL: https://github.com/centralnicgroup-opensource/venom
- Owner: centralnicgroup-opensource
- License: mit
- Created: 2016-08-20T01:48:32.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-08-22T01:21:14.000Z (almost 9 years ago)
- Last Synced: 2025-01-15T19:25:21.037Z (5 months ago)
- Language: Elixir
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Venom
An Elixir JSON encoder that wraps around poison, allowing round tripping of Elixir data types.
## Descriptions
Some of Elixir's native types can't be converted into JSON (and back into Elixir again). This libarary uses [poison](https://github.com/devinus/poison) under the hood to create JSON, but modifies these non convertable types into a JSON-represenation.
## Usage
data = {:tuples, :and, :atoms, :cant, :be :represented, :in, :json}
json = Venom.encode(data)
IO.inspect Venom.decode(json)
# returns: {:tuples, :and, :atoms, :cant, :be :represented, :in, :json}Venom implements all of the [poison JSON conversion functions](https://hexdocs.pm/poison/Poison.html), but wrapped with code to handle special data types.
## Encoding Details
The following Elixir types that aren't valid in JSON are converted.
* tuples: `{"1", 2}` -> `["!tuple", "1", 2]`
* atoms: `:a` -> `":a"`Other conversions prevent injection of special types:
* tuples: `["!tuple", 1]` -> `["!tuple!", 1]`
* atoms: `":a"` -> `"::a"`This list of converted values will probably grow over time.
## Missing Conversions
Non utf8 strings are not yet converted. There may be other things that need conversion; if you find something please raise an issue here.
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed as:
1. Add `venom` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:venom, git: "[email protected]:iwantmyname/venom"}]
end
```2. Ensure `venom` is started before your application:
```elixir
def application do
[applications: [:venom]]
end
```