0

I want to write part of a schema that validates a list of objects, where the objects in the list don't have a name:

"some list": [
    {
        "thing 1": "foo",
        "thing 2": 100
    },
    {
        "thing 1": "foo",
        "thing 2": 100
    },
    {
        "thing 1": "foo",
        "thing 2": 100
    },
]

I have a working schema that has the extra key name that I want to get rid of, labelled I WANT TO GET RID OF THIS NAME. I guess you could think of it as not having a property name for that object.

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "id": "v2",
    "properties": {
        "some list": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "I WANT TO GET RID OF THIS NAME": {
                        "type": "object",
                        "properties": {
                            "thing 1": {
                                "type": "string",
                                "description": "a string"
                            },
                            "thing 2": {
                                "type": "integer",
                                "minimum": 0,
                                "description": "Default time to expose a single image layer for."
                            }
                        },
                        "additionalProperties": false
                    },
                    "additionalProperties": false
                }
            }
        }
    }
}

I can't just git rid of the name because the schema spec expects it, but I also can't figure out how to tell it those objects don't have a name. I am running this example with Python 3.7 using jsonschema Draft7Validator

1 Answer 1

2

You are correct to get rid of that property - it is referring to the wrong level of nesting. The schema should look like:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "id": "v2",
  "properties": {
    "some list": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "thing 1": {
            "type": "string",
            "description": "a string"
          },
          "thing 2": {
            "type": "integer",
            "minimum": 0,
            "description": "Default time to expose a single image layer for."
          }
        },
        "additionalProperties": false
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

I realized I actually removed the wrong name when looking at this. I really wanted to get rid of the names for "thing 1" and "thing 2". I'll post a new question with it, if you know how to fix it, go take a look

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.