[x3d-public] X3D JSON encoding: .x3d to .json stylesheet, examples available for continued work

Don Brutzman brutzman at nps.edu
Wed Oct 28 13:31:50 PDT 2015


Here we go now... 8)

On 10/28/2015 12:51 PM, John Carlson wrote:
> I am still concerned about duplicate keys in JSON.
>
> $ java -jar jslint4java-2.0.4/jslint4java-2.0.4.jar ../examples/X3dForWebAuthors/HelloWorld.json
> jslint:../examples/X3dForWebAuthors/HelloWorld.json:180:19:Duplicate '-children'.
> jslint:../examples/X3dForWebAuthors/HelloWorld.json:244:19:Duplicate '-children'.
>
> On thing is, if I use a JavaScript data structure to store the JSON, merely “copying” over the JSON to JavaScript, the extra duplicates are DROPPED by JavaScript.  It’s GONE!  You can’t get it back.   That means if I use JQuery to naively load the JSON over the network, as my loader does, you lose the earth! And the viewpoint!  Apparently, we have to override the parser in JQuery to get anything.  That means my JSON (loader) to X3DOM converter probably has to be intimately bound to the JSON loading if I want to use JQuery.  I will have to create a data structure that has an array for the duplicates. (WHY CAN’T WE DO THAT IN THE X3D JSON?).  If not, the callbacks from the parser !!! will do X3DOM creation for me.   I will have to seriously revisit how my code is written, and it may get better.  But we really need a good example for people to follow.  I can do this, but it will take some time and thinking.   I don’t know what to expect from other languages, but I 
 guess t
his is
> getting more and more like a JavaScript solution.
>
> At this point, I am unsure if I can even use JQuery, but I will look into it.

Excellent - am reading "we must avoid duplicate keys." Sounds great to me. jQuery compatibility/simplicity is certainly crucial.

I think I can modify the XSLT stylesheet to do just that. Minor side effect: of course if there are multiple contained peer nodes that fill different fields (e.g. children, metadata, proxy, etc. as containerField value), then order of nodes in the original original may get shuffled. Not a showstopper whatsoever, just something we have to document as a limitation of the representation and round-trip conversion. (We might need to add a small rule that ROUTEs always appear last in such a reshuffling to ensure that DEFs occur first - not sure about that one.)

But first... before we each dive into the Abyss of Code Refactoring once again, what about the X3D JSON design pattern? are we doing things in the best way possible?

Am hoping we might sketch out some javascript web author pseudocode, looking at how someone who uses JSONparse might load and modify a Dodecahedron, HelloWorld, or other simple scene graph proposed earlier.

> Here’s the link to my JSON Loader: https://github.com/coderextreme/X3DJSONLD  You should be able to use any web server, but I haven’t tested the loader on other web servers besides node/express.  If you do need to use another web server, make sure there’s a junction or link in the local folder called “examples” pointing to www.web3d.org/x3d/content/examples <http://www.web3d.org/x3d/content/examples> in the local file system It is expected for the X3D Examples to be unpacked in the local file system, not just the JSON (Unless you want to ignore images and inlines, etc.)
>
> My loader works by reading the JSON across the network, then traversing the JavaScript data structure returned to create the X3DOM nodes.

sounds great...  is it runnable via a web page somewhere? or do others have to first install it locally?

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



More information about the x3d-public mailing list