Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update index.md #3

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions _chiron/guides/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,42 @@ Chiron works rather differently to most .NET JSON libraries with which you might

We're still working on a full set of guides to Chiron, but there is already writing out there -- see the [Links][links] section.

## Reading and writing Json values

Chiron is split into `Json<_>` which is for reading and writing JSON and `Json` which is the object model for JSON.

Let's start by writing a discriminated union serialiser:

```fsharp
type DU =
| A
| B
// serialiser
open Chiron
open Chiron.Operators
open Aether
open Aether.Operators
let serialise (d: DU): Json<unit> =
match d with
| A ->
Json.Optic.set Json.String_ "a"
| B ->
Json.Optic.set Json.String_ "b"
```

Similarly, we can write the deserialiser:

```fsharp
let deserialise _: Json<DU> =
function
| "a" -> A
| _ -> B
<!> Json.Optic.get Json.String_
```

That's the very basics. TODO: writing code for fatter objects and choosing to either keep the serialiser inside or outside of the type declaration.


<!--- Local --->

[aether]: /aether
Expand Down