Module: Xml2Json::Json

Defined in:
lib/xml2json.rb

Class Method Summary collapse

Class Method Details

.build(xml, opts: nil) ⇒ String

Note:

Default values are provided by xml2json-rs

Returns JSON string.

Parameters:

  • xml (String, #to_str)

    XML string

  • opts (Hash<Symbol, Object>) (defaults to: nil)

    config params

Options Hash (opts:):

  • attrkey (String, #to_str) — default: "$"

    Key to outer object containing tag attributes

  • charkey (String, #to_str) — default: "_"

    Key to store character content under

  • empty_tag (String, #to_str) — default: ""

    The value of empty nodes

  • indent (bool) — default: false

    Output JSON with line-breaks and indentations

  • explicit_root (bool) — default: true

    Sets the root node inside the resulting object

  • trim (bool) — default: false

    Trim whitespace at the beginning and end of text nodes

  • ignore_attrs (bool) — default: false

    Setting this to true will skip adding element attributes and create text nodes

  • merge_attrs (bool) — default: false

    Merge all XML attributes and child elements as properties of the parent, instead of keying attributes off of the child attribute object. This option will be ignored if ignore_attrs is true

  • normalize_text (bool) — default: false

    Removes whitespace character data in text nodes

  • lowercase_tags (bool) — default: false

    Normalize all tags by converting them to lowercase

  • explicit_array (bool) — default: true

    Always put the child nodes in an array, otherwise an array is only created if there is more than one child

  • explicit_charkey (bool) — default: false

    Always store character data under charkey even if there are no other text elements stored inside the tag

Returns:

  • (String)

    JSON string

Raises:

  • (RuntimeError)

    if xml is not valid XML

  • (TypeError)

    if opts contain invalid value

See Also:



68
# File 'lib/xml2json.rb', line 68

def self.build(xml, opts: nil); end

.build_pretty(xml, opts: nil) ⇒ Object

Note:

Check Xml2Json::Json.build for other details, the only difference is that indent is true by default

Parameters:

  • opts (Hash) (defaults to: nil)

    a customizable set of options

Options Hash (opts:):

  • indent (bool) — default: true

See Also:



72
# File 'lib/xml2json.rb', line 72

def self.build_pretty(xml, opts: nil); end