[x3d-public] How to tell if a file is JSON
Don Brutzman
brutzman at nps.edu
Wed Dec 2 20:45:14 PST 2015
On 11/30/2015 11:25 PM, Leonard Daly wrote:
> Comments are not allowed in a JSON file (I used http://stackoverflow.com/questions/244777/can-i-use-comments-inside-a-json-file and the references contained in the page, especially to json.org, RFC 4627 and RFC 7159).
Good link, now added to related link on X3D to JSON Stylesheet page.
http://www.web3d.org/x3d/stylesheets/X3dToJson.html#comments
Current description
==============================================
*Embedded JSON comments.
Thousands of inquiries have been posted for many years why the JSON specification forbids comments. (Examples: Native comments are intentionally avoided by JSON specification and Can I use comments inside a JSON file?) Without providing a rationale, the suggested JavaScript approach is to use JSON.minify() to strip comments.
Nevertheless, comments are an important capability in the X3D specification. Round-trippable inclusion of comments are an important optional custom feature of this X3D encoding. In order to satisfy JSON single-key requirements, peer comments collected in order as a string array using the #comment keyword, partially reordered as immediate siblings of other sibling nodes.
==============================================
This can be confusing at first. The use of #comment is illustrated multiple times throughout that page.
> Does this approach puts comments into JSON data elements? If so, that means comments have been elevated from text in the file to data in the file. If this approach is to capture comments throughout the original non-JSON file, does that mean the data model between a JSON-encoded scene and an XML-encoded scene is significantly different?
I don't know about elevated, but they are allowed in this X3D JSON encoding. That is semantically different while remaining syntactically correct JSON.
> Out of curiosity, does the compressed binary encoding capture comments from anyplace in the original scene file?
>
> Leonard Daly
For those looking:
http://www.web3D.org > STANDARDS > RECOMMENDED
X3D Compressed Binary Encoding > HTML
4.2.3 X3D canonical form
http://www.web3d.org/documents/specifications/19776-3/V3.3/Part03/concepts.html#X3DCanonicalForm
"i. Comments are always preserved. Since default values for the Compressed binary encoding are lossless, comments are retained by default."
and
"n. Except where specifically overridden by the preceding rules, apply the rules of XML canonicalization, summarized here:
1.comments may optionally be included
2. normalize line feeds
3. normalize attribute values
4. resolve character and parsed entity references
5. sort attributes lexicographically"
The phrasing here might bight be clarified. The intent is to say that comments can be included, that is a choice up to the author or tool. Not much of a rule there - comments can of course be stripped from any file. The key is that yes they are represented correctly in the compressed binary encoding.
> If so, does the data model that is stored in the CBE file match that of the original file?
The data model for .x3d, .x3dv and .x3db are equivalent.
The data model for .x3dj X3D JSON appears to partially sort peer comments, nodes, statements and ROUTEs - everything remains in same first-to-last sequence but similar constructs are collected together into an array.
Saying this well is an upcoming editorial task in the X3D JSON Encoding specification.
> On 11/30/2015 9:27 PM, Don Brutzman wrote:
>> On 11/30/2015 4:23 PM, John Carlson wrote:
>>> There might be a comment before the first x3d object.
>>
>> very interesting observation!
>>
>> - since JSON does not support comments, and
>> - since we have come up with an allowable approach for comments inside an X3D scene graph that allows round-trip support with other encodings,
>>
>> then
>>
>> - we probably ought to deliberately avoid capturing or including any comments in the JSON encoding that might appear outside the "X3D" object declaration.
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