FSharp.Data.JsonValidation


FSharp.Data.JsonValidation

A nifty little DSL for validating JSON against expected schemas.

FSharp.Data.JsonValidation can be installed from NuGet:
PM> Install-Package FSharp.Data.JsonValidation

Example

Validating that a JSON value is exactly "hi" or 42

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
#r "FSharp.Data.JsonValidation.dll"

open FSharp.Data
open JsonValidation

let schema = ExactlyOneOf [JsonValue.String "hi"; JsonValue.Number 42M]

validate schema (JsonValue.String "goodbye")
// returns: Invalid ""Expected value to be one of [\"hi\"; 42] but was \"goodbye\"\""

validate schema (JsonValue.Number 42M)
// returns: Valid

Samples & documentation

  • Tutorial contains a further explanation of this sample library.

  • API Reference contains documentation for types and functions in the library. This includes additional brief examples on using the DSL.

Contributing and copyright

The project is hosted on GitHub where you can report issues, fork the project and submit pull requests. If you're adding a new public API, please also consider adding samples that can be turned into a documentation. You might also want to read the library design notes to understand how it works.

The library is available under Public Domain license, which allows modification and redistribution for both commercial and non-commercial purposes. For more information see the License file in the GitHub repository.

Fork me on GitHub