XmlJson.Parker (XmlJson v0.3.0) View Source

The Parker implementation of XML <=> JSON

https://developer.mozilla.org/en-US/docs/Archive/JXON#The_Parker_Convention

Link to this section Summary

Functions

Deserializes the given XML string. Takes an option (preserve_root, defaults to false) for hoisting the root element or not

Serializes the given Map. Takes an option (preserve_root, defaults to "root") for what property to hoist or inject as the root element

Link to this section Types

Specs

parker_options() ::
  %{preserve_root: boolean() | binary()}
  | [{:preserve_root, boolean() | binary()}]

Link to this section Functions

Link to this function

deserialize(xml, opts \\ [])

View Source

Specs

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

Deserializes the given XML string. Takes an option (preserve_root, defaults to false) for hoisting the root element or not

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

Examples

iex> XmlJson.Parker.deserialize("<alice>bob</alice>")
{:ok, "bob"}

iex> XmlJson.Parker.deserialize("<alice>bob</alice>", preserve_root: true)
{:ok, %{"alice" => "bob"}}
Link to this function

deserialize!(xml, opts \\ [])

View Source

Specs

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

serialize(object, opts \\ [])

View Source

Specs

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

Serializes the given Map. Takes an option (preserve_root, defaults to "root") for what property to hoist or inject as the root element

Returns an :ok tuple with the Map serialized to XML

Examples

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

iex> XmlJson.Parker.serialize(%{"alice" => "bob"}, preserve_root: "alice")
{:ok, "<alice>bob</alice>"}
Link to this function

serialize!(map, opts \\ [])

View Source

Specs

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