Malcolm Dwyer

Developer|Runner|Lego Nut|Photographer|Dad

JSON Predicate

2015-9-28

json-predicate is a Javascript library I built that allows a JSON document to describe validations and other conditional options for another set of data.

Background: At my job, we develop web applications that are used by our internal customers. I build front-ends and work with someone else who handles the Java backend. One challenge in building these apps is when and where to validate user input.

Since the API will be accessible from potentially several different clients, we definitely need validations on the backend. Leaving it at that, the application would work, but the user experience is not ideal. An invalid value can only be discovered after submitting a form or taking action. We want to build UIs that can work dynamically to constrain inputs, show the user when something is not valid, and in some cases, provide dynamically generated options based on other selections.

This is where JSON predicate comes in.

I went looking around online for some way of programmatically describing validations and came across Jason Snell's JSON-Precicate Spec. It's a good, straightforward way of building predicates in a JSON format, so I decided to build a JavaScript implementation of it.

Github logo Jump over to the github project to take a look.