XmlJson.BadgerFish (XmlJson v0.5.0) View Source

The BadgerFish implementation of XML <=> JSON

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

Link to this section Summary

Link to this section Types

Specs

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

Link to this section Functions

Link to this function

deserialize(xml, opts \\ [])

View Source

Specs

deserialize(binary(), badgerfish_options()) :: {:ok, map()} | {:error, term()}

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

deserialize!(xml, opts \\ [])

View Source

Specs

deserialize!(binary(), badgerfish_options()) :: map()
Link to this function

serialize(object, opts \\ [])

View Source

Specs

serialize(map(), badgerfish_options()) :: {:ok, binary()} | {:error, term()}

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>"}
Link to this function

serialize!(map, opts \\ [])

View Source

Specs

serialize!(map(), badgerfish_options()) :: binary()