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
Link to this section Functions
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"}}
Specs
deserialize!(binary(), parker_options()) :: map()
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>"}
Specs
serialize!(map(), parker_options()) :: binary()