XmlJson.BadgerFish (XmlJson v0.2.0) View Source

The BadgerFish implementation of XML <=> JSON

http://www.sklar.com/badgerfish/

Link to this section Summary

Functions

Deserializes the given XML string.

Serializes the given Map.

Link to this section Types

Specs

badgerfish_options() ::
  %{exclude_namespaces: boolean()} | [{:exclude_namespaces, boolean()}]

Link to this section Functions

Link to this function

deserialize(xml, opts \\ [])

View Source

Specs

deserialize(binary(), badgerfish_options()) :: {:ok, map()}

Deserializes the given XML string.

Returns an :ok tuple with the XML deserialized to a Map

Examples

iex> XmlJson.BadgerFish.deserialize("<alice>bob</alice>")
{:ok, %{"alice" => %{"$" => "bob"}}}

iex> XmlJson.BadgerFish.deserialize("<alice xmlns=\"https://default.example.com\">bob</alice>", exclude_namespaces: true)
{:ok, %{"alice" => %{"$" => "bob"}}}
Link to this function

serialize(object, opts \\ [])

View Source

Specs

serialize(map(), badgerfish_options()) :: {:ok, binary()}

Serializes the given Map.

Returns an :ok tuple with a Map serialized to XML

Examples

iex> XmlJson.BadgerFish.serialize(%{"alice" => %{"$" => "bob"}})
{:ok, "<alice>bob</alice>"}

iex> XmlJson.BadgerFish.serialize(%{"alice" => %{"$" => "bob", "@xmlns" => %{"$" => "https://default.example.com"}}}, exclude_namespaces: true)
{:ok, "<alice>bob</alice>"}