Packages

Convert between XML and JSON using the BadgerFish specification

Current section

Files

Jump to
xmljson src xmljson.erl
Raw

src/xmljson.erl

-module(xmljson).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([to_json/1, to_xml_fragment/1, to_xml/1]).
-file("/home/edwin/Documents/code/gleam/badgerfish/src/xmljson.gleam", 8).
-spec to_json(binary()) -> {ok, gleam@json:json()} |
{error, xmljson@element:decode_error()}.
to_json(Input) ->
_pipe = xmljson@element:from_xml(Input),
gleam@result:map(_pipe, fun(Elem) -> xmljson@element:to_json(Elem) end).
-file("/home/edwin/Documents/code/gleam/badgerfish/src/xmljson.gleam", 14).
-spec to_xml_fragment(binary()) -> {ok, binary()} |
{error, gleam@json:decode_error()}.
to_xml_fragment(Input) ->
_pipe = xmljson@element:from_json(Input),
gleam@result:map(_pipe, fun(Elem) -> _pipe@1 = Elem,
_pipe@2 = xmljson@element:to_xml_type(_pipe@1),
_pipe@3 = xmb_ffi:identity(_pipe@2),
unicode:characters_to_binary(_pipe@3) end).
-file("/home/edwin/Documents/code/gleam/badgerfish/src/xmljson.gleam", 25).
-spec to_xml(binary()) -> {ok, binary()} | {error, gleam@json:decode_error()}.
to_xml(Input) ->
_pipe = xmljson@element:from_json(Input),
gleam@result:map(
_pipe,
fun(Elem) ->
X = begin
_pipe@1 = Elem,
xmljson@element:to_xml_type(_pipe@1)
end,
_pipe@2 = xmb:render([X]),
unicode:characters_to_binary(_pipe@2)
end
).