Parse and validate json payloads and query strings.


Keywords
License
Apache-2.0
Install
Install-Package Saon -Version 1.0.2-pre7

Documentation

Saon: parse and validate JSON

GitHub Workflow Status Nuget Nuget (with prereleases)

WARNING: this is an early release of Saon. Expect the API to change.

Goals

  • Parse idiomatic json payloads into strongly-typed F# objects
  • Convert json types (string, number, object, array) to F# types
  • Continue validating the payload even after one validation fails. This is planned for after FS-1063 lands
  • Provide enough information to produce helpful error response

Usage & Tutorials

type Email = Email of string
type ContactDetails =
    { Name : string
      Email : Email }

let parseEmail =
    Validate.isNotEmptyOrWhitespace
    /> Validate.isEmail
    /> Convert.withFunction Email

let parseContactDetails = jsonObjectParser {
    let! name = Json.property "name" (Json.string /> Validate.isNotEmptyOrWhitespace)
    let! email = Json.property "email" (Json.string /> parseEmail)
    return { Name = name; Email = email }
}

We also provide tutorials to help you get started:

Similar Libraries

Saon was inspired by other libraries:

LICENSE

Copyright 2020 Francesco Ceccon

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.