X3D JSON Encoding
These are X3D Working Group notes on the creation of an X3D JSON encoding and corresponding conversion processes.
Design Requirements, Goals and Use Cases
- Round-trippable encoding supporting X3D abstract specification
Design goals and primary use cases:
- Exchange format for a variety of 3D geometry and scene graphs
- Are there any use cases that might modify how X3D is represented in JSON?
- If so, it would be good to spell them out and understand them well.
- We want conversion rules to permit implementations that can achieve user goals.
Guideline: the more that this work has progressed, the more the JSON output resembles VRML/ClassicVrml structure with slight differences in syntax. This approach has a valuable extra benefit in that results are broadly understandable by many object-oriented programmers.
X3D to JSON Stylesheet Converter, an experimental effort to help create a JSON encoding for X3D Graphics.
- JSON translations for all of the 3800+ scenes in X3D Example Archives have been deployed.
- Conversion support included in X3D-Edit for testing of new examples by authors
- Conversion syntax discussions continue on x3d-public mail list and x3dom-developers mail list (with "dump scene as json" test by Dr. Yvonne Jung)
Related work in progress: X3D JSON loader to test round-trippability works satisfactorily
This X3D JSON Encoding page is periodically refreshed based on implementation/evaluation results.
Primary design criterion: round-trippable lossless representation of X3D scene.
Conversion approach of greatest practical interest: XML to/from JSON. Issues:
- How to convert attribute names to distinguish them from child elements. Resolution: "@attributeName".
- JSON handling of container elements to preserve parent/child relationships, distinguishing child elements from attributes Resolution: use SFNode/MFNode field names as unique keys.
- Creation of JSON elements with datatypes appropriate to content (e.g., integer, float, strings, etc.). Note special JSON rules for floats (not equivalent to IEEE floats).
- jslint-validatable field/fieldValue representations within Scripts and prototypes
- Support for singleton (self-closing) XML tags also needs to be considered, without loss of generality.
- Inclusion and preservation of embedded XML namespace information in an XML (.x3d) document: might not be necessary or possible.
The X3D to JSON Stylesheet Converter considers these and other interoperability issues in great detail.
Probably smartest to first start out defining an X3D best practice.
The most probable place to put it is as a new Part 5 to ISO/IEC 19776. In this manner, it would correspond to the XML, Classic VRML, and Compressed Binary encodings.
Here are suggested discussion points for X3D teleconferences and future followups.
- Is there a good/consistent way for X3DOM, Cobweb or other tools to utilize such capabilities?
- Is there a single authoritative reference for JSON itself? and for JSON-XML conversions? See  for the JSON Data Interchange Format, need to confirm no others.
- IETF (referencing ECMA) states that
.jsonis the standard extension
- Internet MIME-type is
- IETF (referencing ECMA) states that
- Can a file reader distinguish the incoming encodings (.x3d .x3dv .x3db .x3de .json/.x3dj) independent of file extension or MIME media type?
- Compare compression size and decompression speed of a TestMesh.x3d.json.gz to TestMesh.x3db and TestMesh.x3d.exi (EXI will likely win because it includes data typing)
Lots of progress continues.
- Roy Walmsley, Don Brutzman and John Carlson, "A JSON Encoding for X3D", Web3D 2016 Conference, Anaheim California, 22-24 July 2016.
- JSLint validation
- X3D JSON loader, https://github.com/coderextreme/X3DJSONLD
- X3D to JSON Stylesheet Converter, http://www.web3d.org/x3d/stylesheets/X3dToJson.html
- 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
- ECMA 404: JSON Data Interchange Format (Final Draft) http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf
- JSON Markup Language (JsonML) http://www.jsonml.org
- XSLTJSON: Transforming XML to JSON using XSLT http://www.bramstein.com/projects/xsltjson
- Converting Between XML and JSON http://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html
- XML/JSON Perl Converter http://search.cpan.org/~ken/XML-XML2JSON-0.06/lib/XML/XML2JSON.pm
- IBM's PHP converter http://www.ibm.com/developerworks/library/x-xml2jsonphp
- Java Converter http://www.json.org/javadoc/org/json/XML.html
- Google Code Library https://code.google.com/p/x2js
Mailing list discussions