Using JavaScript for validation?

41 views
Skip to first unread message

di...@heyboyo.com

unread,
Mar 29, 2017, 4:25:16 AM3/29/17
to JSON Schema
Is it possible to use JavaScript in the JSON Schema definition to validate values?

As a made up example, let's say I have integers A, B, and C, and I want to write some JavaScript that needs to look at all three to validate the form. The JavaScript could be something from a one line expression, to a multiline function.

Is this something that' supported within the specification of the schema, or through other methods?

Cheers,
Diego

Ben Hutton (@Relequestual)

unread,
Mar 29, 2017, 4:28:17 AM3/29/17
to JSON Schema, di...@heyboyo.com
Nope.

JSON Schema is a language agnostic specification. Although JSON is the medium, JSON IS supported by many languages. It's not in any way limited to javascript.

Plus, generally you're either using the a schema from someone else, or giving it to someone else. Including arbitrary code in such a document sounds like a bad idea to me.

In addition, if you're looking to validate a form, you should validate it client side AND server side. Just be careful! =]

Henry Andrews

unread,
Mar 29, 2017, 4:34:44 AM3/29/17
to json-...@googlegroups.com, di...@heyboyo.com
Agreed, although something that could very easily drive that kind of client-side form validation may be in scope for https://github.com/json-schema-org/json-schema-spec/issues/67

cheers,
-henry



From: "Ben Hutton (@Relequestual)" <b...@sanger.ac.uk>
To: JSON Schema <json-...@googlegroups.com>
Cc: di...@heyboyo.com
Sent: Wednesday, March 29, 2017 1:28 AM
Subject: [json-schema] Re: Using JavaScript for validation?

--
You received this message because you are subscribed to the Google Groups "JSON Schema" group.
To unsubscribe from this group and stop receiving emails from it, send an email to json-schema...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Ben Hutton (@Relequestual)

unread,
Mar 29, 2017, 9:08:29 AM3/29/17
to JSON Schema, di...@heyboyo.com, andrew...@yahoo.com
Sure! But we wouldn't want to include actual javascript as values in the JSON.
To unsubscribe from this group and stop receiving emails from it, send an email to json-schema+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages