https://github.com/njlr/thoth-json-ce
Computation Expression for building Thoth.Json decoders
https://github.com/njlr/thoth-json-ce
computation-expressions decoder fable fsharp json
Last synced: 5 months ago
JSON representation
Computation Expression for building Thoth.Json decoders
- Host: GitHub
- URL: https://github.com/njlr/thoth-json-ce
- Owner: njlr
- License: mit
- Created: 2022-03-18T10:44:43.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-11-21T19:24:23.000Z (over 3 years ago)
- Last Synced: 2025-11-04T23:12:43.131Z (8 months ago)
- Topics: computation-expressions, decoder, fable, fsharp, json
- Language: F#
- Homepage:
- Size: 21.5 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Thoth.Json.CE
Create `Thoth.Json` decoders using a Computation Expression.
```fsharp
#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:
```bash
# Fable
paket add Thoth.Json.CE
# .NET
paket add Thoth.Json.Net.CE
```
Install as a file using [Paket](https://fsprojects.github.io/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
```