Skip to content

[bug-ish] Improperly formatted JSON text doesn't trigger error in Common Validation #191

Description

@flaneuse

Describe the bug
In the schema editor, I'm creating Common Validation properties. It's a bit tricky to hand-write .json and easy to introduce errors. When there's a typo/json-syntax error, a SyntaxError is created in the console, but the user has no indication that there's something wrong w/ the the input. It's easy to assume that the definition was saved -- when it wasn't.

To Reproduce
Steps to reproduce the behavior:
Try to declare this as a validation object ;).

{
  "anyOf": [{
      "@type": "Person",
      "description": "Reusable person definition",
      "properties": {
        "affiliation": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string"
            },
            "sameAs": {
              "type": "string"
            },
            "url": {
              "type": "string",
              "format": "uri"
            }
          },
          "required": ["name"],
          "optional": ["sameAs", "url"]
        },
        "name": {
          "type": "string"
        },
        "email": {
          "type": "string"
        },
        "familyName": {
          "type": "string"
        },
        "givenName": {
          "type": "string"
        },
        "identifier": {
          "type": "string"
        },
        "role": {
          "type": "string"
        },
        "title": {
          "type": "string"
        },
        "url": {
          "type": "string",
          "format": "uri"
        }
      },
      "required": [
        "name"
      ],
      "recommended: ["
      familyName ", "
      givenName ", "
      identifier "],
      "optional": ["affiliation", "email", "role", "title", "url"]
      "type": "object"
    },
    {
      "items": {
        "@type": "Person",
        "description": "Reusable person definition",
        "properties": {
          "name": {
            "type": "string"
          }
        },
        "required": [
          "name"
        ],
        "type": "object"
      },
      "type": "array"
    },
    {
      "@type": "Organization",
      "description": "Reusable organization definition",
      "properties": {
        "name": {
          "type": "string"
        }
      },
      "required": [
        "name"
      ],
      "type": "object"
    },
    {
      "items": {
        "@type": "Organization",
        "description": "Reusable organization definition",
        "properties": {
          "name": {
            "type": "string"
          }
        },
        "required": [
          "name"
        ],
        "type": "object"
      },
      "type": "array"
    }
  ]
}

Error output
You get console errors like:

editor:1 Uncaught SyntaxError: Unexpected non-whitespace character after JSON at position 7

Uncaught SyntaxError: Unexpected token 'f', ..."mended: ["familyName"... is not valid JSON

Expected behavior

  • Alert the user that the property has a syntax error and hasn't been saved
  • It'd be nice to have a JSON formatter/beautifier down the road... JSON is hard to write with all the nesting, in a small window. Incorporate some sort of JSON linter?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions