[X3D-Public] x3d to json experiments & links of interest

Don Brutzman brutzman at nps.edu
Tue Jul 1 22:04:18 PDT 2014


Recently there has been some talk about JSON representations for X3D.  Looks pretty easy.

Leonard Daly requested discussion on this topic Wednesday during the regular X3D working group teleconference.  Here are inputs.

=====================================================================

1.  Test scene:  HelloWorld.x3d in various forms as

source
	http://www.web3d.org/x3d/content/examples/Basic/HelloWorld.x3d
pretty print
	http://www.web3d.org/x3d/content/examples/Basic/HelloWorld.html
X3DOM
	http://www.web3d.org/x3d/content/examples/Basic/HelloWorld.xhtml
XML
	http://www.web3d.org/x3d/content/examples/Basic/HelloWorldCanonical.xml

=====================================================================

2. Altova XMLSpy advertises this capability as a built-in feature, with round-trip conversion.

http://blog.altova.com/2013/03/editing-converting-and-generating-json.html

Didn't work for me (producing an empty .json file) until I selected Grid View and highlighted/selected the entire document.  Looks straightforward, result attached as HelloWorldAltovaXMLSpy.json

Then performed a round trip conversion.  Sorta worked but attributes got turned into elements, and <!-- XML comments --> got turned into <Comment> elements.  Attached as
HelloWorldAltovaXMLSpy.json.roundtrip.xml

=====================================================================

3.  Then tried an online converter.  Here is one:

http://www.utilities-online.info/xmltojson

JSON conversion result looks good:

{
   "X3D": {
     "-profile": "Immersive",
     "-version": "3.3",
     "-xmlns:xsd": "http://www.w3.org/2001/XMLSchema-instance",
     "-xsd:noNamespaceSchemaLocation": "http://www.web3d.org/specifications/x3d-3.3.xsd",
     "head": {
       "meta": [
         {
           "-content": "HelloWorld.x3d",
           "-name": "title"
         },
         {
           "-content": "Simple X3D example: Hello World!",
           "-name": "description"
         },
         {
           "-content": "30 October 2000",
           "-name": "created"
         },
         {
           "-content": "16 August 2013",
           "-name": "modified"
         },
         {
           "-content": "Don Brutzman",
           "-name": "creator"
         },
         {
           "-content": "HelloWorld.tall.png",
           "-name": "Image"
         },
         {
           "-content": "http://en.wikipedia.org/wiki/Hello_world",
           "-name": "reference"
         },
         {
           "-content": "http://en.wikibooks.org/w/index.php?title=Computer_Programming/Hello_world",
           "-name": "reference"
         },
         {
           "-content": "http://www.HelloWorldExample.net",
           "-name": "reference"
         },
         {
           "-content": "http://www.web3D.org",
           "-name": "reference"
         },
         {
           "-content": "http://www.web3d.org/realtime-3d/news/internationalization-x3d",
           "-name": "reference"
         },
         {
           "-content": "http://www.web3d.org/x3d/content/examples/HelloWorld.x3d",
           "-name": "reference"
         },
         {
           "-content": "http://X3dGraphics.com/examples/X3dForAdvancedModeling/HelloWorldScenes",
           "-name": "reference"
         },
         {
           "-content": "http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter01-TechnicalOverview/HelloWorld.x3d",
           "-name": "identifier"
         },
         {
           "-content": "http://www.web3d.org/x3d/content/examples/license.html",
           "-name": "license"
         },
         {
           "-content": "X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit",
           "-name": "generator"
         },
         {
           "-content": "HelloWorld.wrl",
           "-name": "reference"
         },
         {
           "-content": "HelloWorld.x3dv",
           "-name": "reference"
         },
         {
           "-content": "HelloWorld.x3db",
           "-name": "reference"
         },
         {
           "-content": "HelloWorld.xhtml",
           "-name": "reference"
         }
       ]
     },
     "Scene": {
       "Group": {
         "Viewpoint": {
           "-DEF": "ViewUpClose",
           "-centerOfRotation": "0 -1 0",
           "-description": "Hello world!",
           "-position": "0 -1 7"
         },
         "Transform": [
           {
             "-rotation": "0 1 0 3",
             "Shape": {
               "Appearance": {
                 "Material": {
                   "-DEF": "MaterialLightBlue",
                   "-diffuseColor": "0.1 0.5 1"
                 },
                 "ImageTexture": {
                   "-DEF": "ImageCloudlessEarth",
                   "-url": "\"earth-topo.png\" \"earth-topo.jpg\" \"earth-topo-small.gif\" \"http://www.web3d.org/x3d/content/examples/Basic/earth-topo.png\" \"http://www.web3d.org/x3d/content/examples/Basic/earth-topo.jpg\" \"http://www.web3d.org/x3d/content/examples/Basic/earth-topo-small.gif\""
                 }
               }
             }
           },
           {
             "-translation": "0 -2 0",
             "Shape": {
               "Text": {
                 "-DEF": "TextMessage",
                 "-string": "\"Hello\" \"world!\"",
                 "FontStyle": { "-justify": "\"MIDDLE\" \"MIDDLE\"" }
               },
               "Appearance": {
                 "Material": { "-USE": "MaterialLightBlue" }
               }
             }
           }
         ]
       }
     }
   }
}

Conversion issues:
- DOCTYPE info got dropped
- comments got dropped
- singleton element <Sphere/> got dropped
- note that attributes got prefixed by a hyphen

Attached as file HelloWorld-utilities-online.info.json

Round trip also looked good, with proper reconstruction of alternatives apparently enabled by the hyphen characters (which got stripped out on the return trip).  Some differences in quoting but all within the legal variations allowed by XML and unambiguously consistent with original source.  Result .xml rendered OK by InstantPlayer, minus the dropped Sphere.  Round-trip success.

Attached asHelloWorld-utilities-online.info.roundtrip.xml

=====================================================================

4.  Search revealed numerous other resources online, here are a few:

XML to JSON Converter
(provides option to assign a prefix to JSON attributes, default is @ character)
http://www.freeformatter.com/xml-to-json-converter.html

Apache Camel, XML JSON Data Format (camel-xmljson)
http://camel.apache.org/xmljson.html

JSON Markup Language (JsonML)
http://www.jsonml.org/

XSLTJSON: Transforming XML to JSON using XSLT
http://www.bramstein.com/projects/xsltjson/

I tried this last one using Netbeans for the XSLT conversion.  It worked, though output was minimized by default (no line feeds or indents).  Reformatted, attached as HelloWorld.XSLTJSON.json

Looks like that XSLT worked.  There are some others out there.  Note that XSLT can convert XML -> JSON but not the other way around.

=====================================================================

5.  Also found some search results for X3DOM JSON

X3DOM Example
http://jsfiddle.net/jcarlile/9U7Bf/

json-stringify-safe - X3DOM
http://www.x3dom.org/x3dom/test/regression-suite/node_modules/request/node_modules/json-stringify-safe/

[X3D-Public] Web3D Timeline Demo - conversion to X3DOM
http://www.web3d.org/pipermail/x3d-public_web3d.org/2012-April/001974.html
"The actual work to convert x3d/Proto to x3dom/json was done by nils (cced)"

x3dom / Discussion / Open Discussion:Loading large X3D models
https://sourceforge.net/p/x3dom/discussion/957285/thread/15e494b8/

x3dom - Efficient Binary Meshes
http://www.web3d.org/realtime-3d/files/documents/S2012/x3dom_Efficient-Binary-Meshes_behr.pdf

=====================================================================

6.  Suggested discussion points for the X3D teleconference and future followups.

a.  What are the use cases for having X3D JSON available in JavaScript?  It would be good to spell them out and understand them well.
b.  Is there a good/consistent way for X3DOM to utilize such capabilities?
c.  Is there a way for Three.js or other javascript libraries to utilize such capabilities?
d.  Is there a single authoritative reference for JSON itself? and for JSON-XML conversions?
e.  Compare compression of a TestMesh.x3d.json.gz to TestMesh.x3db and TestMesh.x3d.exi
	(EXI will likely win because it includes data typing)
f.  Once a canonical form for X3D as JSON is established, add conversion capabilities to X3D-Edit and also autoconvert, test and publish JSON for all of the3800+ X3D Examples Archive scenes
g.  Decide if this capability needs to be defined in one of the X3D standards, or perhaps as an X3D best practice.
h.  Probably lots more... What else?

all the best, Don
-- 
Don Brutzman  Naval Postgraduate School, Code USW/Br       brutzman at nps.edu
Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   +1.831.656.2149
X3D graphics, virtual worlds, navy robotics http://faculty.nps.edu/brutzman
-------------- next part --------------
A non-text attachment was scrubbed...
Name: HelloWorld.x3d
Type: model/x3d+xml
Size: 3062 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20140701/400bb54e/attachment-0001.x3d>
-------------- next part --------------
{
	"XML": {
		"version": 1.0,
		"encoding": "UTF-8"
	},
	"X3D": {
		"PUBLIC": "\"ISO//Web3D//DTD X3D 3.3//EN\" \"http://www.web3d.org/specifications/x3d-3.3.dtd\""
	},
	"X3D": {
		"profile": "Immersive",
		"version": 3.3,
		"xmlns:xsd": "http://www.w3.org/2001/XMLSchema-instance",
		"xsd:noNamespaceSchemaLocation": "http://www.web3d.org/specifications/x3d-3.3.xsd",
		"head": {
			"meta": [
				{
					"content": "HelloWorld.x3d",
					"name": "title"
				}, {
					"content": "Simple X3D example: Hello World!",
					"name": "description"
				}, {
					"content": "30 October 2000",
					"name": "created"
				}, {
					"content": "16 August 2013",
					"name": "modified"
				}, {
					"content": "Don Brutzman",
					"name": "creator"
				}, {
					"content": "HelloWorld.tall.png",
					"name": "Image"
				}, {
					"content": "http://en.wikipedia.org/wiki/Hello_world",
					"name": "reference"
				}, {
					"content": "http://en.wikibooks.org/w/index.php?title=Computer_Programming/Hello_world",
					"name": "reference"
				}, {
					"content": "http://www.HelloWorldExample.net",
					"name": "reference"
				}, {
					"content": "http://www.web3D.org",
					"name": "reference"
				}, {
					"content": "http://www.web3d.org/realtime-3d/news/internationalization-x3d",
					"name": "reference"
				}, {
					"content": "http://www.web3d.org/x3d/content/examples/HelloWorld.x3d",
					"name": "reference"
				}, {
					"content": "http://X3dGraphics.com/examples/X3dForAdvancedModeling/HelloWorldScenes",
					"name": "reference"
				}, {
					"content": "http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter01-TechnicalOverview/HelloWorld.x3d",
					"name": "identifier"
				}, {
					"content": "http://www.web3d.org/x3d/content/examples/license.html",
					"name": "license"
				}, {
					"content": "X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit",
					"name": "generator"
				}
			],
			"Comment": " Alternate encodings: VRML97, X3D ClassicVRML Encoding, X3D Compressed Binary Encoding (CBE), X3DOM ",
			"meta": [
				{
					"content": "HelloWorld.wrl",
					"name": "reference"
				}, {
					"content": "HelloWorld.x3dv",
					"name": "reference"
				}, {
					"content": "HelloWorld.x3db",
					"name": "reference"
				}, {
					"content": "HelloWorld.xhtml",
					"name": "reference"
				}
			]
		},
		"Scene": {
			"Comment": " Example scene to illustrate X3D nodes and fields (XML elements and attributes) ",
			"Group": {
				"Viewpoint": {
					"DEF": "ViewUpClose",
					"centerOfRotation": "0 -1 0",
					"description": "Hello world!",
					"position": "0 -1 7"
				},
				"Transform": {
					"rotation": "0 1 0 3",
					"Shape": {
						"Sphere": "",
						"Appearance": {
							"Material": {
								"DEF": "MaterialLightBlue",
								"diffuseColor": "0.1 0.5 1"
							},
							"ImageTexture": {
								"DEF": "ImageCloudlessEarth",
								"url": "\"earth-topo.png\" \"earth-topo.jpg\" \"earth-topo-small.gif\" \"http://www.web3d.org/x3d/content/examples/Basic/earth-topo.png\" \"http://www.web3d.org/x3d/content/examples/Basic/earth-topo.jpg\" \"http://www.web3d.org/x3d/content/examples/Basic/earth-topo-small.gif\""
							}
						}
					}
				},
				"Transform": {
					"translation": "0 -2 0",
					"Shape": {
						"Text": {
							"DEF": "TextMessage",
							"string": "\"Hello\" \"world!\"",
							"FontStyle": {
								"justify": "\"MIDDLE\" \"MIDDLE\""
							}
						},
						"Appearance": {
							"Material": {
								"USE": "MaterialLightBlue"
							}
						}
					}
				}
			}
		}
	}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: HelloWorldAltovaXMLSpy.json.roundtrip.xml
Type: text/xml
Size: 4090 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20140701/400bb54e/attachment-0002.xml>
-------------- next part --------------
{
  "X3D": {
    "-profile": "Immersive",
    "-version": "3.3",
    "-xmlns:xsd": "http://www.w3.org/2001/XMLSchema-instance",
    "-xsd:noNamespaceSchemaLocation": "http://www.web3d.org/specifications/x3d-3.3.xsd",
    "head": {
      "meta": [
        {
          "-content": "HelloWorld.x3d",
          "-name": "title"
        },
        {
          "-content": "Simple X3D example: Hello World!",
          "-name": "description"
        },
        {
          "-content": "30 October 2000",
          "-name": "created"
        },
        {
          "-content": "16 August 2013",
          "-name": "modified"
        },
        {
          "-content": "Don Brutzman",
          "-name": "creator"
        },
        {
          "-content": "HelloWorld.tall.png",
          "-name": "Image"
        },
        {
          "-content": "http://en.wikipedia.org/wiki/Hello_world",
          "-name": "reference"
        },
        {
          "-content": "http://en.wikibooks.org/w/index.php?title=Computer_Programming/Hello_world",
          "-name": "reference"
        },
        {
          "-content": "http://www.HelloWorldExample.net",
          "-name": "reference"
        },
        {
          "-content": "http://www.web3D.org",
          "-name": "reference"
        },
        {
          "-content": "http://www.web3d.org/realtime-3d/news/internationalization-x3d",
          "-name": "reference"
        },
        {
          "-content": "http://www.web3d.org/x3d/content/examples/HelloWorld.x3d",
          "-name": "reference"
        },
        {
          "-content": "http://X3dGraphics.com/examples/X3dForAdvancedModeling/HelloWorldScenes",
          "-name": "reference"
        },
        {
          "-content": "http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter01-TechnicalOverview/HelloWorld.x3d",
          "-name": "identifier"
        },
        {
          "-content": "http://www.web3d.org/x3d/content/examples/license.html",
          "-name": "license"
        },
        {
          "-content": "X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit",
          "-name": "generator"
        },
        {
          "-content": "HelloWorld.wrl",
          "-name": "reference"
        },
        {
          "-content": "HelloWorld.x3dv",
          "-name": "reference"
        },
        {
          "-content": "HelloWorld.x3db",
          "-name": "reference"
        },
        {
          "-content": "HelloWorld.xhtml",
          "-name": "reference"
        }
      ]
    },
    "Scene": {
      "Group": {
        "Viewpoint": {
          "-DEF": "ViewUpClose",
          "-centerOfRotation": "0 -1 0",
          "-description": "Hello world!",
          "-position": "0 -1 7"
        },
        "Transform": [
          {
            "-rotation": "0 1 0 3",
            "Shape": {
              "Appearance": {
                "Material": {
                  "-DEF": "MaterialLightBlue",
                  "-diffuseColor": "0.1 0.5 1"
                },
                "ImageTexture": {
                  "-DEF": "ImageCloudlessEarth",
                  "-url": "\"earth-topo.png\" \"earth-topo.jpg\" \"earth-topo-small.gif\" \"http://www.web3d.org/x3d/content/examples/Basic/earth-topo.png\" \"http://www.web3d.org/x3d/content/examples/Basic/earth-topo.jpg\" \"http://www.web3d.org/x3d/content/examples/Basic/earth-topo-small.gif\""
                }
              }
            }
          },
          {
            "-translation": "0 -2 0",
            "Shape": {
              "Text": {
                "-DEF": "TextMessage",
                "-string": "\"Hello\" \"world!\"",
                "FontStyle": { "-justify": "\"MIDDLE\" \"MIDDLE\"" }
              },
              "Appearance": {
                "Material": { "-USE": "MaterialLightBlue" }
              }
            }
          }
        ]
      }
    }
  }
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: HelloWorld-utilities-online.info.roundtrip.xml
Type: text/xml
Size: 2779 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20140701/400bb54e/attachment-0003.xml>
-------------- next part --------------
["X3D", {
        "profile": "Immersive",
        "version": 3.3,
        "xsd:noNamespaceSchemaLocation": "http://www.web3d.org/specifications/x3d-3.3.xsd"
    }, ["head", ["meta", {
                "content": "HelloWorld.x3d",
                "name": "title"
            }], ["meta", {
                "content": "Simple\nX3D\nexample:\nHello\nWorld!",
                "name": "description"
            }], ["meta", {
                "content": "30\nOctober\n2000",
                "name": "created"
            }], ["meta", {
                "content": "16\nAugust\n2013",
                "name": "modified"
            }], ["meta", {
                "content": "Don\nBrutzman",
                "name": "creator"
            }], ["meta", {
                "content": "HelloWorld.tall.png",
                "name": "Image"
            }], ["meta", {
                "content": "http://en.wikipedia.org/wiki/Hello_world",
                "name": "reference"
            }], ["meta", {
                "content": "http://en.wikibooks.org/w/index.php?title=Computer_Programming/Hello_world",
                "name": "reference"
            }], ["meta", {
                "content": "http://www.HelloWorldExample.net",
                "name": "reference"
            }], ["meta", {
                "content": "http://www.web3D.org",
                "name": "reference"
            }], ["meta", {
                "content": "http://www.web3d.org/realtime-3d/news/internationalization-x3d",
                "name": "reference"
            }], ["meta", {
                "content": "http://www.web3d.org/x3d/content/examples/HelloWorld.x3d",
                "name": "reference"
            }], ["meta", {
                "content": "http://X3dGraphics.com/examples/X3dForAdvancedModeling/HelloWorldScenes",
                "name": "reference"
            }], ["meta", {
                "content": "http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter01-TechnicalOverview/HelloWorld.x3d",
                "name": "identifier"
            }], ["meta", {
                "content": "http://www.web3d.org/x3d/content/examples/license.html",
                "name": "license"
            }], ["meta", {
                "content": "X3D-Edit\n3.3,\nhttps://savage.nps.edu/X3D-Edit",
                "name": "generator"
            }], [""], ["meta", {
                "content": "HelloWorld.wrl",
                "name": "reference"
            }], ["meta", {
                "content": "HelloWorld.x3dv",
                "name": "reference"
            }], ["meta", {
                "content": "HelloWorld.x3db",
                "name": "reference"
            }], ["meta", {
                "content": "HelloWorld.xhtml",
                "name": "reference"
            }]], ["Scene", [""], ["Group", {
                "bboxCenter": "0\n0\n0",
                "bboxSize": "-1\n-1\n-1",
                "containerField": "children"
            }, ["Viewpoint", {
                    "DEF": "ViewUpClose",
                    "centerOfRotation": "0\n-1\n0",
                    "description": "Hello\nworld!",
                    "position": "0\n-1\n7",
                    "fieldOfView": "0.7854",
                    "jump": true,
                    "orientation": "0\n0\n1\n0",
                    "retainUserOffsets": false,
                    "containerField": "children"
                }], ["Transform", {
                    "rotation": "0\n1\n0\n3",
                    "center": "0\n0\n0",
                    "scale": "1\n1\n1",
                    "scaleOrientation": "0\n0\n1\n0",
                    "translation": "0\n0\n0",
                    "bboxCenter": "0\n0\n0",
                    "bboxSize": "-1\n-1\n-1",
                    "containerField": "children"
                }, ["Shape", {
                        "containerField": "children",
                        "bboxCenter": "0\n0\n0",
                        "bboxSize": "-1\n-1\n-1"
                    }, ["Sphere", {
                            "radius": 1,
                            "solid": true,
                            "containerField": "geometry"
                        }], ["Appearance", {
                            "containerField": "appearance"
                        }, ["Material", {
                                "DEF": "MaterialLightBlue",
                                "diffuseColor": "0.1\n0.5\n1",
                                "ambientIntensity": "0.2",
                                "emissiveColor": "0\n0\n0",
                                "shininess": "0.2",
                                "specularColor": "0\n0\n0",
                                "transparency": 0,
                                "containerField": "material"
                            }], ["ImageTexture", {
                                "DEF": "ImageCloudlessEarth",
                                "url": "\"earth-topo.png\"\n\"earth-topo.jpg\"\n\"earth-topo-small.gif\"\n\"http://www.web3d.org/x3d/content/examples/Basic/earth-topo.png\"\n\"http://www.web3d.org/x3d/content/examples/Basic/earth-topo.jpg\"\n\"http://www.web3d.org/x3d/content/examples/Basic/earth-topo-small.gif\"",
                                "repeatS": true,
                                "repeatT": true,
                                "containerField": "texture"
                            }]]]], ["Transform", {
                    "translation": "0\n-2\n0",
                    "center": "0\n0\n0",
                    "rotation": "0\n0\n1\n0",
                    "scale": "1\n1\n1",
                    "scaleOrientation": "0\n0\n1\n0",
                    "bboxCenter": "0\n0\n0",
                    "bboxSize": "-1\n-1\n-1",
                    "containerField": "children"
                }, ["Shape", {
                        "containerField": "children",
                        "bboxCenter": "0\n0\n0",
                        "bboxSize": "-1\n-1\n-1"
                    }, ["Text", {
                            "DEF": "TextMessage",
                            "string": "\"Hello\"\n\"world!\"",
                            "maxExtent": "0.0",
                            "solid": false,
                            "containerField": "geometry"
                        }, ["FontStyle", {
                                "justify": "\"MIDDLE\"\n\"MIDDLE\"",
                                "family": "\"SERIF\"",
                                "horizontal": true,
                                "leftToRight": true,
                                "size": 1.0,
                                "spacing": 1.0,
                                "style": "PLAIN",
                                "topToBottom": true,
                                "containerField": "fontStyle"
                            }]], ["Appearance", {
                            "containerField": "appearance"
                        }, ["Material", {
                                "USE": "MaterialLightBlue",
                                "ambientIntensity": "0.2",
                                "diffuseColor": "0.8\n0.8\n0.8",
                                "emissiveColor": "0\n0\n0",
                                "shininess": "0.2",
                                "specularColor": "0\n0\n0",
                                "transparency": 0,
                                "containerField": "material"
                            }]]]]]]]


More information about the X3D-Public mailing list