Skip to content

Computation Expression for building Thoth.Json decoders

License

Notifications You must be signed in to change notification settings

njlr/thoth-json-ce

Repository files navigation

Thoth.Json.CE

Create Thoth.Json decoders using a Computation Expression.

#r "nuget: Thoth.Json.Net.CE"

open System

#if FABLE_COMPILER
open Thoth.Json
open Thoth.Json.CE
#else
open Thoth.Json.Net
open Thoth.Json.Net.CE
#endif

type Book =
  {
    ID : Guid
    Title : string
    Year : int
  }

module Book =

  let decode =
    decoder {
      let! id = Decode.field "id" Decode.guid
      let! title = Decode.field "title" Decode.string
      let! year = Decode.field "year" Decode.int

      return
        {
          ID = id
          Title = title
          Year = year
        }
    }
    
"""
{
  "id": "f3394dca-1620-46a3-a850-ee2fc11f5b6c",
  "title": "The Player of Games",
  "year": "1988"
}
"""
|> Decode.fromString Book.decode
|> printfn "%A"

Install

Install from NuGet:

# Fable
paket add Thoth.Json.CE

# .NET
paket add Thoth.Json.Net.CE

Install as a file using Paket:

Add this line to your paket.dependencies:

github njlr/thoth-json-ce thoth-json-ce/Thoth.Json.CE.fs

Add this line to your paket.references:

File: Thoth.Json.CE.fs

About

Computation Expression for building Thoth.Json decoders

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages