Voglio convalidare l'input da un modulo HTML utilizzando uno schema JSON che lo descrive. Sto usando JSV di Gary Court per convalidarlo e restituisce un errore in modo coerente. Ho usato JSON Schema Lint (jsonschemalint.com) per controllare il mio schema. In Chrome Schema Lint mi dice che il mio schema è valido, ma in Firefox, Safari & Opera, il sito web mi dice che il mio schema è JSON valido ma non valido schema JSON. Qualcuno mi può aiutare. Il mio schema è sottoCome convalidare un modulo utilizzando JSON Schema?
AGGIORNAMENTO 8/6/13 Grazie per tutte le vostre risposte. Il mio JSON aggiornato (aggiornato di seguito) è ora valido in tutti i browser. Tuttavia ancora sto ottenendo il seguente errore da JSV:
Report {errors: Array[1], validated: Object, instance: JSONInstance, schema: JSONSchema, schemaSchema: JSONSchema…}
errors: Array[1]
0: Object
attribute: "type"
details: Array[1]
0: "object"
length: 1
__proto__: Array[0]
message: "Instance is not a required type"
schemaUri: "http://json-schema.org/draft-03/hyper-schema#"
uri: "urn:uuid:808fe74b-b0d0-4774-8975-289f105dfeaa#"
__proto__: Object
length: 1
__proto__: Array[0]
instance: JSONInstance
schema: JSONSchema
schemaSchema: JSONSchema
validated: Object
__proto__: Report
Permettetemi di dire che io possa essere interpretare il messaggio di errore in modo non corretto. Tuttavia sono abbastanza sicuro che si riferisca alla linea "type": "object"
direttamente dopo la parentesi graffa aperta. Tuttavia, la chiave "type": "object"
: value fa parte della specifica Draft 03 su http://tools.ietf.org/html/draft-zyp-json-schema-03. Ciò è fonte di confusione perché JSON Schema Lint usa anche la libreria JSV ... Grazie per tutto il tuo aiuto fino ad ora.
{
"type": "object",
"$schema": "http://json-schema.org/draft-03/schema#",
"title": "FormValidation",
"description": "Describes the types of and valid inputs to a form generated via Form Creator",
"properties": {
"Air Temperature (C)": {
"type": "number",
"description": "Air Temperature measurement in centigrade.",
"required": false
},
"Ammonia": {
"type": "number",
"description": "Ammonia measurement at test site.",
"required": false
},
"Aquatic Life Present": {
"type": "string",
"description": "Are organisms such as fish or frogs living near the test site?",
"required": false
},
"Chlorophyll a": {
"type": "number",
"description": "Chlorophyll a measurement at test site.",
"required": false
},
"Conductivity": {
"type": "number",
"description": "Water conductivity measurement at test site.",
"required": false
},
"Date of Test": {
"type": "string",
"description": "Date the measurements were recorded.",
"required": true
},
"Dissolved Oxygen 1": {
"type": "number",
"description": "Disolved oxygen reading at first depth.",
"required": false
},
"Dissolved Oxygen 2": {
"type": "number",
"description": "Dissolved oxygen reading at second depth.",
"required": false
},
"Latitude": {
"type": "number",
"description": "Latitude of the measurement site in degrees.",
"required": true
},
"Longitude": {
"type": "number",
"description": "Longitude of the measurement site in degrees.",
"required": true
},
"Nitrates": {
"type": "number",
"description": "Nitrate measurement at test site.",
"required": false
},
"Orthophosphates": {
"type": "number",
"description": "Orthophosphate measurement at site of testing.",
"required": false
},
"Phosphates": {
"type": "number",
"description": "Phosphate reading at measurement site.",
"required": false
},
"Secchi Disk": {
"type": "number",
"description": "Secchi Disk depth reading at measurement site.",
"required": false
},
"Site Change": {
"type": "string",
"description": "Has the site undergone noticeable physical change since the last measuring event?",
"required": false
},
"Test Site": {
"type": "string",
"description": "Location where the measurements were recorded.",
"required": true
},
"Turbidity (ntu)": {
"type": "number",
"description": "Cloudiness or haziness of water, measured in Nephelometric Turbidity Units (NTU).",
"required": false
},
"Water Color or Odor": {
"type": "string",
"description": "Does the water have an strange colorations or emit a noticeable odor?",
"required": false
},
"Water Temperature (C)": {
"type": "number",
"description": "Water Temperature measurement in centigrade.",
"required": false
},
"pH": {
"type": "number",
"description": "pH measurement at test site.",
"required": false
}
}
}
potrebbe essere "richiesto" può essere solo "vero" o "falso" all'inizio? hai impostato un numero di valori non booleani. –
Prova anche questo: http://jsonlint.com/ –