News for hackers. Stuff that matters.
Re:Ask HN: Do you use JSON Schema? Help us shape its future ... by magicalhippo on Monday January 30, 2023 @11:05PM (#34590885)
I must admit I'm a noob in this world so maybe I'm going about it the wrong way, but I used JSON Schema's oneOf[1] along with required[2] for this:

    "properties": {
      "cat": {
        "$ref": "#/$defs/catType"
      }
      "dog": {
        "$ref": "#/$defs/dogType"
      }
    },
    "oneOf": [
      {
        "required": ["cat"]
      },
      {
        "required": ["dog"]
      },
    ]
Usage would then look like:

    {
      "dog": {
        "name": "Charlie"
      }
    }
At least it's explicit and can be easily checked for validity.

[1]: https://json-schema.org/understanding-json-schema/reference/...

[2]: https://json-schema.org/understanding-json-schema/reference/...

Re:Ask HN: Do you use JSON Schema? Help us shape its future ... by com2kid on Tuesday January 31, 2023 @03:57PM (#34601954)