I'd like to use Fable.JsonConverter.
My test code (almost copy this) FableJson.fs
is below,
module FableJson
open Newtonsoft.Json
// Always use the same instance of the converter
// as it will create a cache to improve performance
let private jsonConverter = Fable.JsonConverter() :> JsonConverter
// Serialization
let toJson value =
JsonConvert.SerializeObject(value, [|jsonConverter|])
// Deserialization
let ofJson<'T> json =
JsonConvert.DeserializeObject<'T>(json, [|jsonConverter|])
and paket.dependencies
file added nuget Fable.JsonConverter
source https://nuget.org/api/v2
storage:none
clitool dotnet-fable
nuget Fable.Core
nuget Fable.Import.Browser
nuget Fable.JsonConverter
and src/paket.references
file added Fable.JsonConverter
dotnet-fable
Fable.Core
Fable.Import.Browser
Fable.JsonConverter
But cannnot compile.
~~~ snip ~~~
ERROR in ./src/FableJson.fs
d:/SRC/Repos/Fable/testJsonConverter/src/FableJson.fs(11,4): (11,57) error FABLE: Cannot find replacement for Newtonsoft.Json.JsonConvert::SerializeObject
@ ./src/App.fs 6:0-48
@ ./src/testJsonConverter.fsproj
@ multi (webpack)-dev-server/client?http://localhost:8080 ./src/testJsonConverter.fsproj
ERROR in ./src/FableJson.fs
d:/SRC/Repos/Fable/testJsonConverter/src/FableJson.fs(15,4): (15,62) error FABLE: Cannot find replacement for Newtonsoft.Json.JsonConvert::DeserializeObject
@ ./src/App.fs 6:0-48
@ ./src/testJsonConverter.fsproj
@ multi (webpack)-dev-server/client?http://localhost:8080 ./src/testJsonConverter.fsproj
ERROR in ./src/FableJson.fs
d:/SRC/Repos/Fable/testJsonConverter/src/FableJson.fs(7,28): (7,49) error FABLE: Cannot find replacement for Fable.JsonConverter::.ctor
@ ./src/App.fs 6:0-48
@ ./src/testJsonConverter.fsproj
@ multi (webpack)-dev-server/client?http://localhost:8080 ./src/testJsonConverter.fsproj
What should I do?
@Maslow is right, with Fable 2 we removed Fable.JsonConverter in favour of the library created by the community.
Thoth.Json is complemented with Thoth.Json.Net to allow you to use the same API on the backend.
I think Fable.SimpleJson also offer supports for the backend, but I am not sure.
You can use the JavaScript native API Fable.Core.JS.JSON.stringify
and Fable.Core.JS.JSON.parse(x)
but you will have to use unbox
/cast to force the type of your Data which is not safe and can break easily.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With