Validieren Sie den spezifischen Wert in Jsonschema mit Python

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Validieren Sie den spezifischen Wert in Jsonschema mit Python

by Anonymous » 11 Apr 2025, 12:08

Freunde, angesichts der Struktur unten, wie man validieren, wenn das Feld "title" das Wert "Delectus Autem"
enthalten muss. Ich würde auch gerne wissen, ob das -Gender Feld "männlich/weiblich" als ich auch validieren würde.

Code: Select all

def test_get():
response = requests.get(ENDPOINT)
assert response.status_code == 200
data = response.json()
print(data)
print(data['title'])

def test_body():
schema = {
"type": "object",
"properties": {
"id": {"type": "integer"},
"title": {"type": "string"},

},
}

validate(instance={"id": 1, "title": "delectus aut autem"}, schema=schema)
# No error, the JSON is valid.

Top