afs_json_xmlize - AFS - Reference Guides

AFS Filters Description

Product
AFS
Platform
7.11
Category
Reference Guides
Language
English

Convert JSON data to XML.

The filter is declared with the afs_json_xmlize type. It is in the antidot-paf-misc package. It is a processor filter.

This filter can be instantiated only once at any given moment. It will not read the "instances" parameter in the configuration.

The Convert JSON to XML filter specifications are described in the following table:

Parameter name

Mandatory

Type

Default

Description

input_layer

No

layer

CONTENTS

It is the input layer.

output_layer

No

layer

USER_1

It is the output layer.

default_namespace

No

string

No namespace used

The default namespace

Example, using this filter, these JSON data:
        {
      "glossary": {
        "title": "example glossary",
        "GlossDiv": {
            "title": "S",
            "GlossList": {
                "GlossEntry": {
                    "ID": "SGML",
                    "SortAs": "SGML",
                    "GlossTerm": "Standard Generalized Markup Language",
                    "Acronym": "SGML",
                    "Abbrev": "ISO 8879:1986",
                    "GlossDef": {
                        "GlossSeeAlso": ["GML", "XML"],
                        "para": "A meta-markup language, used to create markup languages such as DocBook."
                    },
                    "GlossSee": "markup"
                }
            }
        }
    }
}
will be converted to:
<?xml version='1.0' encoding='UTF-8'?>
<root>
  <glossary>
    <title>example glossary</title>
    <GlossDiv>
      <title>S</title>
      <GlossList>
        <GlossEntry>
          <ID>SGML</ID>
          <SortAs>SGML</SortAs>
          <GlossTerm>Standard Generalized Markup Language</GlossTerm>
          <Acronym>SGML</Acronym>
          <Abbrev>ISO 8879:1986</Abbrev>
          <GlossDef>
            <GlossSeeAlso>
              <element>GML</element>
              <element>XML</element>
            </GlossSeeAlso>
            <para>A meta-markup language, used to create markup languages such as DocBook.</para>
          </GlossDef>
          <GlossSee>markup</GlossSee>
        </GlossEntry>
      </GlossList>
    </GlossDiv>
  </glossary>
</root> 
Some JSON may use XML-invalid characters. For instance, this JSON:
{"$id":5}
will be converted to:
<?xml version='1.0' encoding='UTF-8'?>
<root>
  <_0x24_id origin="$id">5</_0x24_id>
</root>

Tip: Note that this is a bijective transformation. The "origin" attribute is only set if there is a special character.