What is the best way to deal with deserializing JSON? For example, if the JSON you are trying to deserialize has a bunch of nested properties, modelling it with Types seems really, really verbose and cumbersome. Is there a better way?
How about some sort of dynamic (gasp) type in F#? Also, to complicate things, I am using .NET Core and FSharp.Data doesn’t work yet, so no JSON Type Converter. Which would be perfect!
I think FSharp.Data works with .NET Core (I’m using it right now), but it’s in beta. If you’re using Paket, you’ll have to pin it to the pre-release beta version (https://www.nuget.org/packages/FSharp.Data/3.0.0-beta3).
I don’t know that there’s a “best” way…Json.NET suits my needs about 90% of the time. Sure, it struggles a bit with more complicated F# types (something like Map<(RandomRecord1 * RandomRecord2), int>), but you can either have a function that converts your domain type into a less complicated “POFO” that Json.NET can handle or write a custom JsonConverter.
I like Thoth.Json. It can be used for both .NET and Fable code.
It’s a bit more work to define decoders and encoders for your types but you get type safety.
You should really have a look at Fleece since AFAIK provides all the functionality of the above mentioned libs plus the possibility to use overloading (for implicit codecs), a single synchronized method for serialization/deserialization and choice of FSharp.Data, Newtonsoft or System.Json.