Poison

From Elixir Wiki
Jump to navigation Jump to search

Poison[edit]

File:PoisonLogo.png
Poison logo

Poison is a fast, flexible, and feature-rich Elixir library for dealing with JSON. It enables developers to encode and decode JSON data effortlessly, making it an essential tool for working with web APIs, data exchange, and various other scenarios where JSON is involved.

Features[edit]

  • Fully supports the JSON spec defined in RFC 8259.
  • Provides a simple and intuitive API for encoding and decoding JSON.
  • Can handle complex data structures, including nested maps, lists, and tuples.
  • Efficiently handles large data sets and supports streaming for improved performance.
  • Offers advanced options for customization, such as custom encoders, decoders, and transformations.
  • Supports encoding and decoding of user-defined types, extending the library's capabilities.

Installation[edit]

To use Poison in your Elixir project, simply add it as a dependency in your `mix.exs` file:

```elixir defp deps do

 [
   {:poison, "~> 4.0"}
 ]

end ```

Then, run `mix deps.get` to fetch the dependency.

Usage[edit]

Once Poison is included in your project, you can easily start encoding and decoding JSON data.

To encode an Elixir data structure into JSON:

```elixir json = Poison.encode(%{key: "value"}) ```

To decode JSON data into an Elixir structure:

```elixir data = Poison.decode!(json) ```

You can also specify options during encoding or decoding:

```elixir json = Poison.encode(%{key: "value"}, keys: :atoms) data = Poison.decode!(json, keys: :atoms) ```

For more detailed examples and information on how to use Poison effectively, check out the Poison Examples page.

Further Resources[edit]

  • Poison Guides - A comprehensive guide to using Poison effectively.
  • Poison Examples - A collection of practical examples demonstrating Poison's capabilities.
  • Poison Changelog - Release notes and version history of Poison.

Note: Before using Poison in your project, it is recommended to refer to the Poison GitHub repository for the latest updates and documentation.

Template:ProgrammingLanguages