[x3d-public] JSON validation

Don Brutzman brutzman at nps.edu
Mon Mar 6 16:26:10 PST 2017


interesting issue fixed

On 3/6/2017 3:32 PM, Don Brutzman wrote:
>[...]
> Found one problem scene (taken from specification) which includes intentionally challenging quotations:
>
>     http://www.web3d.org/x3d/content/examples/Basic/X3dSpecifications/X3dHeaderPrototypeSyntaxExamples.x3d
>
>     http://www.web3d.org/x3d/content/examples/Basic/X3dSpecifications/X3dHeaderPrototypeSyntaxExamplesIndex.html
>
>     http://www.web3d.org/x3d/content/examples/Basic/X3dSpecifications/X3dHeaderPrototypeSyntaxExamples.json
>
>     http://jsonlint.com/?json=http://www.web3d.org/x3d/content/examples/Basic/X3dSpecifications/X3dHeaderPrototypeSyntaxExamples.json
>
> =============================================
> Error: Parse error on line 231:
> ... "#comment": "alternative: Text s
> -----------------------^
> Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'
> =============================================
[...]
> Original .x3d form:
>
> <Shape containerField='proxy'>
>     <Text string='"He said, \"Immel did it!\""'/>
>     <!-- alternative: Text string='"He said, \"Immel did it!\""' -->
>     <Appearance>
>         <Material/>
>     </Appearance>
> </Shape>
>
> So the Text MFString is handled OK but the comment is not.  Shouldn't be hard to fix, will look at that.

Corrected translation follows:

{ "Shape":
   {
     "-geometry":
       { "Text":
         {
           "@string":["He said, \"Immel did it!\""]
         }
       },
     "-children":[
       {
         "#comment":"alternative: Text string='\"He said, \\\"Immel did it!\\\"\"'"
       }
     ],
     "-appearance":
       { "Appearance":
         {
           "-material":
             { "Material":
               {
               }
             }
         }
       }
   }
},

This was an interesting case because, within the #comment, an additional level of quoting is applied and so an additional level of escaped escaping + escaped quoting is involved. In plainer words, \" became \\\" within the "value of the comment".

Corrected valid json scene attached, will run updated X3dToJson.xslt against all other examples and hopefully no side effects have crept in.

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 --------------
{ "X3D": {
    "encoding":"UTF-8",
    "@profile":"Immersive",
    "@version":"3.2",
    "@xsd:noNamespaceSchemaLocation":"http://www.web3d.org/specifications/x3d-3.2.xsd",
    "JSON schema":"http://www.web3d.org/specifications/x3d-3.3-JSONSchema.json",
    "head": {
        "component": [
          {
            "@name":"Geospatial",
            "@level":1
          },
          {
            "@name":"NURBS",
            "@level":2
          },
          {
            "@name":"Core",
            "@level":2
          },
          {
            "@name":"Navigation",
            "@level":1
          },
          {
            "@name":"Text",
            "@level":1
          }
        ],
        "meta": [
          {
            "@name":"title",
            "@content":"X3dHeaderPrototypeSyntaxExamples.x3d"
          },
          {
            "@name":"description",
            "@content":"X3D scene header and prototype syntax examples. This example header indicates that the content is XML encoded, follows the Interactive Profile and explicitly lists additional necessary components. The X3D header may also contain additional semantic information. Used for specification EXAMPLE excerpts in 19776:1 XML Encoding."
          },
          {
            "@name":"created",
            "@content":"14 October 2002"
          },
          {
            "@name":"modified",
            "@content":"26 November 2015"
          },
          {
            "@name":"creator",
            "@content":"Don Brutzman"
          },
          {
            "@name":"specificationSection",
            "@content":"X3D encodings, ISO/IEC 19776-1.3, Part 1: XML encoding, 4.3 XML file syntax"
          },
          {
            "@name":"specificationUrl",
            "@content":"http://www.web3d.org/documents/specifications/19776-1/V3.3/Part01/concepts.html#XMLFileSyntax"
          },
          {
            "@name":"identifier",
            "@content":"http://www.web3d.org/x3d/content/examples/Basic/X3dSpecifications/X3dHeaderPrototypeSyntaxExamples.x3d"
          },
          {
            "@name":"generator",
            "@content":"X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit"
          },
          {
            "@name":"license",
            "@content":"../license.html"
          },
          {
            "@name":"translated",
            "@content":"06 March 2017"
          },
          {
            "@name":"generator",
            "@content":"X3dToJson.xslt, http://www.web3d.org/x3d/stylesheets/X3dToJson.html"
          },
          {
            "@name":"warning",
            "@content":"An experimental version of X3D JSON encoding is used for this scene.  Status online at http://www.web3d.org/wiki/index.php/X3D_JSON_Encoding"
          }
        ]
    },
    "Scene": {
        "-children":[
          { "ExternProtoDeclare":
            {
              "@name":"ViewPositionOrientation",
              "@url":["../../Savage/Tools/Authoring/ViewPositionOrientationPrototype.x3d#ViewPositionOrientation","https://savage.nps.edu/Savage/Tools/Authoring/ViewPositionOrientationPrototype.x3d#ViewPositionOrientation","../../Savage/Tools/Authoring/ViewPositionOrientationPrototype.wrl#ViewPositionOrientation","https://savage.nps.edu/Savage/Tools/Authoring/ViewPositionOrientationPrototype.wrl#ViewPositionOrientation"],
              "field": [
                {
                  "@name":"enabled",
                  "@accessType":"inputOutput",
                  "@type":"SFBool"
                },
                {
                  "@name":"traceEnabled",
                  "@accessType":"initializeOnly",
                  "@type":"SFBool"
                },
                {
                  "@name":"set_traceEnabled",
                  "@accessType":"inputOnly",
                  "@type":"SFBool"
                },
                {
                  "@name":"position_changed",
                  "@accessType":"outputOnly",
                  "@type":"SFVec3f"
                },
                {
                  "@name":"orientation_changed",
                  "@accessType":"outputOnly",
                  "@type":"SFRotation"
                },
                {
                  "@name":"outputViewpointString",
                  "@accessType":"outputOnly",
                  "@type":"MFString"
                }
              ]
            }
          },
          { "ProtoDeclare":
            {
              "@name":"NewWorldInfoNode",
              "ProtoBody": {
                  "-children":[
                    { "WorldInfo":
                      {
                        "@DEF":"ExamplePrototypeBody"
                      }
                    }
                  ]
              }
            }
          },
          { "ProtoInstance":
            {
              "@name":"NewWorldInfoNode"
            }
          },
          { "ProtoDeclare":
            {
              "@name":"EmissiveMaterial",
              "ProtoInterface": {
                  "field": [
                    {
                      "@name":"onlyColor",
                      "@accessType":"inputOutput",
                      "@type":"SFColor",
                      "@value":[1,0,0]
                    }
                  ]
              },
              "ProtoBody": {
                  "-children":[
                    { 
                      "#comment":"Override default diffuseColor value 0.8 0.8 0.8"
                    },
                    { "Material":
                      {
                        "@diffuseColor":[0,0,0],
                        "-children":[
                          { 
                            "#comment":"Connect emissiveColor field of current node to onlyColor field of parent ProtoDeclare."
                          }
                        ],
                        "IS": {
                            "connect": [
                              {
                                "@nodeField":"emissiveColor",
                                "@protoField":"onlyColor"
                              }
                            ]
                        }
                      }
                    }
                  ]
              }
            }
          },
          { "ProtoDeclare":
            {
              "@name":"ShiftGroupUp2m",
              "ProtoInterface": {
                  "field": [
                    {
                      "@name":"children",
                      "@accessType":"inputOutput",
                      "@type":"MFNode",
                      "-children":[
                        { "Group":
                          {
                            "@DEF":"DefaultNodeValue",
                            "@bboxSize":[2,2,2],
                            "-children":[
                              { 
                                "#comment":"Authors need to override this node when creating the ProtoInstance fieldValue name=\"children\""
                              }
                            ]
                          }
                        }
                      ]
                    }
                  ]
              },
              "ProtoBody": {
                  "-children":[
                    { "Transform":
                      {
                        "@translation":[0,2,0],
                        "-children":[
                          { "Group":
                            {
                              "IS": {
                                  "connect": [
                                    {
                                      "@nodeField":"children",
                                      "@protoField":"children"
                                    }
                                  ]
                              }
                            }
                          }
                        ]
                      }
                    }
                  ]
              }
            }
          },
          { "ProtoInstance":
            {
              "@name":"ShiftGroupUp2m"
            }
          },
          { 
            "#comment":"===================="
          },
          { "Viewpoint":
            {
              "@DEF":"ExampleSingleElement",
              "@description":"Hello syntax"
            }
          },
          { "Group":
            {
              "@DEF":"ExampleChildElement",
              "-children":[
                { "Shape":
                  {
                    "-geometry":
                      { "Box":
                        {
                        }
                      },
                    "-appearance":
                      { "Appearance":
                        {
                          "-material":
                            { "Material":
                              {
                                "@diffuseColor":[0.6,0.4,0.2]
                              }
                            }
                        }
                      }
                  }
                }
              ]
            }
          },
          { "Transform":
            {
              "@DEF":"TransformExampleUSE",
              "@rotation":[0,1,0,0.78],
              "@translation":[0,2.5,0],
              "-children":[
                { "Group":
                  {
                    "@USE":"ExampleChildElement"
                  }
                }
              ]
            }
          },
          { "Collision":
            {
              "-proxy":
                { "Shape":
                  {
                    "-geometry":
                      { "Text":
                        {
                          "@string":["He said, \"Immel did it!\""]
                        }
                      },
                    "-children":[
                      { 
                        "#comment":"alternative: Text string='\"He said, \\\"Immel did it!\\\"\"'"
                      }
                    ],
                    "-appearance":
                      { "Appearance":
                        {
                          "-material":
                            { "Material":
                              {
                              }
                            }
                        }
                      }
                  }
                },
              "-children":[
                { "Group":
                  {
                    "@USE":"ExampleChildElement"
                  }
                }
              ]
            }
          },
          { "Transform":
            {
              "@translation":[0,-2.5,0],
              "-children":[
                { "Shape":
                  {
                    "-appearance":
                      { "Appearance":
                        {
                          "-material":
                            { "ProtoInstance":
                              {
                                "@name":"EmissiveMaterial",
                                "fieldValue": [
                                  {
                                    "@name":"onlyColor",
                                    "@value":[0.2,0.6,0.6]
                                  }
                                ]
                              }
                            }
                        }
                      },
                    "-geometry":
                      { "Text":
                        {
                          "@string":["X3D Header Prototype syntax examples","(view console for EXTERNPROTO output)"],
                          "-fontStyle":
                            { "FontStyle":
                              {
                                "@justify":["MIDDLE","MIDDLE"],
                                "@size":0.6
                              }
                            }
                        }
                      }
                  }
                }
              ]
            }
          },
          { "ProtoInstance":
            {
              "@name":"ViewPositionOrientation",
              "fieldValue": [
                {
                  "@name":"enabled",
                  "@value":true
                }
              ]
            }
          },
          { "TimeSensor":
            {
              "@DEF":"Clock",
              "@cycleInterval":4,
              "@loop":true
            }
          },
          { "OrientationInterpolator":
            {
              "@DEF":"Spinner",
              "@key":[0,0.5,1],
              "@keyValue":[0,1,0,0,0,1,0,3.14159,0,1,0,6.28318]
            }
          },
          { "ROUTE":
            {
              "@fromField":"fraction_changed",
              "@fromNode":"Clock",
              "@toField":"set_fraction",
              "@toNode":"Spinner"
            }
          },
          { "ROUTE":
            {
              "@fromField":"value_changed",
              "@fromNode":"Spinner",
              "@toField":"rotation",
              "@toNode":"TransformExampleUSE"
            }
          },
          { "Inline":
            {
              "@DEF":"someInline",
              "@url":["someUrl.x3d","http://www.web3d.org/x3d/content/examples/Basic/X3dSpecifications/someUrl.x3d"]
            }
          },
          { "PositionInterpolator":
            {
              "@DEF":"StayInPlace",
              "@key":[0,1],
              "@keyValue":[0,0,0,0,0,0]
            }
          },
          { "ROUTE":
            {
              "@fromField":"fraction_changed",
              "@fromNode":"Clock",
              "@toField":"set_fraction",
              "@toNode":"StayInPlace"
            }
          },
          { "ROUTE":
            {
              "@fromField":"value_changed",
              "@fromNode":"StayInPlace",
              "@toField":"set_translation",
              "@toNode":"someInlineRoot"
            }
          }
        ],
        "IMPORT": [
          {
            "@AS":"someInlineRoot",
            "@importedDEF":"someName",
            "@inlineDEF":"someInline"
          }
        ]
    }
  }
}


More information about the x3d-public mailing list