xyncro / chiron

JSON for F#
https://xyncro.tech/chiron
MIT License
175 stars 41 forks source link

Could use a nicer way of writing empty properties for DUs #26

Closed haf closed 8 years ago

haf commented 9 years ago

Like:

type T =
 | A
 | B
 static member ToJson (t : T) =
  match t with
  | A -> Json.write "a" (None : string option)
  | B -> Json.write "b" (None : string option)

instead perhaps

Json.writeNullProp "a"

kolektiv commented 9 years ago

Yes, that could be handy. Will add.

haf commented 9 years ago

Ping?

kolektiv commented 9 years ago

Will try this and if it works nicely will include it in 5.0

kolektiv commented 9 years ago

https://github.com/kolektiv/chiron/commit/ad5bf47d25920ef5f1e469725e01b3d8a01b346e includes Json.writeNone for such cases. Although wondering if writeNullwould be better...

haf commented 9 years ago

Yes, probably. Nice

CumpsD commented 8 years ago

Seems this is released and working, just tried it in 6.0.1

Json.writeNone "bla" results in:

"hash": {
   "bla": null
},

Probably can close