Format Tree as JSON (vuo.tree.format.json)

Turns a tree (including descendants) into JSON-formatted text.

If the tree was created with text fed into the Make Tree from JSON node, this node outputs the original JSON information, preserving the data types of JSON numbers, booleans, and null values. Otherwise, the tree is translated to JSON format, with all content translated to JSON strings.

A tree that has just a name and content, no attributes or children, is turned into a JSON object, like this:

{ "title" : "China Mountain Zhang" }

If a tree has children, and each child has a unique name, the tree is turned into a JSON object with sub-objects, like this:

{ "book" :
   { "title" : "China Mountain Zhang",
     "author" : "Maureen F. McHugh"

If some of the tree’s children have the same name, they’re turned into a JSON array, like this:

{ "book" :
   { "award" :
      [ "James Tiptree, Jr. Memorial Award",
        "Lambda Literary Award",
        "Locus Award for Best First Novel"

A tree’s attributes, like its children, are turned into JSON sub-objects, like this:

{ "book" :
   { "isbn" : "0312852711",
     "publisher" : "Tor Books"

If a tree or any of its descendants lack names, names are added, like this:

{ "document" : "Mandarin" }
{ "document":
   "item": [ 1992, 1994, 1998, 2001 ]

Keywords: convert, export, save, serialize, text, write

Example composition:

Back to vuo.tree node set documentation.