FSharpCompiler.Json
1.2.0
The new package implements all the features of this package and has a better API.
dotnet add package FSharpCompiler.Json --version 1.2.0
NuGet\Install-Package FSharpCompiler.Json -Version 1.2.0
<PackageReference Include="FSharpCompiler.Json" Version="1.2.0" />
paket add FSharpCompiler.Json --version 1.2.0
#r "nuget: FSharpCompiler.Json, 1.2.0"
// Install FSharpCompiler.Json as a Cake Addin #addin nuget:?package=FSharpCompiler.Json&version=1.2.0 // Install FSharpCompiler.Json as a Cake Tool #tool nuget:?package=FSharpCompiler.Json&version=1.2.0
FSharpCompiler.Json
FSharpCompiler.Json
is a easy to use and configurable JSON framework for F#.
Flexible JSON serializer for converting between F# type and JSON.
DU
Json
type for manually reading and writing JSON.The Urljson format is used for tree structure data for URL queries. It's shorter than the Json format.
Features
JsonFormatter
The function JsonFormatter.serialize
serializes an instance of a type into a JSON string.
JsonFormatter.serialize:'t -> string
For example:
let r = {| x = 0; y = false; |}
let y = JsonFormatter.serialize r
should.equal y """{"x":0,"y":false}"""
The function JsonFormatter.deserialize
converts the JSON string into an instance of a given type.
JsonFormatter.deserialize: string -> 't
For example:
let json = """{"x":0,"y":false}"""
let y = JsonFormatter.deserialize<{|x:int;y:bool|}> json
let obj = {| x = 0; y = false; |}
should.equal y obj
The function JsonFormatter.serializeDynamic
is Dynamic serialization, which converts reflected type and instance data into a JSON string.
JsonFormatter.serializeDynamic: Type -> obj -> string
For example:
let obj = {| x = 0; y = false; |}
let y = JsonFormatter.serializeDynamic typeof<{|x:int;y:bool|}> obj
should.equal y """{"x":0,"y":false}"""
The function JsonFormatter.deserializeDynamic
is Dynamic deserialization that converts the given JSON string into instances of a given type.
JsonFormatter.deserializeDynamic: Type -> string -> obj
For example:
let json = """{"x":0,"y":false}"""
let y = JsonFormatter.deserializeDynamic typeof<{|x:int;y:bool|}> json
let obj = box {| x = 0; y = false; |}
should.equal y obj
UrlQuery
The module UrlQuery
represents the Query part of an url.
The function UrlQuery.parseField
resolves the field value of a single key value pair in the query string as an instance of an F# type.
UrlQuery.parseField: string -> 't
For example:
let x = "[`xyz`,`123`]"
let y = UrlQuery.parseField<string[]> x
let z = [|"xyz";"123"|]
should.equal y z
The function UrlQuery.parse
resolves the entire query string to an instance of F# type.
UrlQuery.parse: seq<string*string> -> 't
For example:
let pairs = ["foo","bar";"abc","[`xyz`,`123`]"]
let y = UrlQuery.parse<{|foo:string;abc:string[]|}> pairs
let z = {|abc=[|"xyz";"123"|];foo="bar"|}
should.equal y z
This function UrlQuery.parseFieldDynamic
dynamically resolves a single field value of a query string for an instance of a given type.
UrlQuery.parseFieldDynamic: Type -> string -> obj
For example:
let urljson = "[`xyz`,`123`]"
let y = UrlQuery.parseFieldDynamic typeof<string[]> urljson
let z = box [|"xyz";"123"|]
should.equal y z
The function UrlQuery.parseQueryDynamic
dynamically resolves a single field value of a query as an object instance of the given F# type.
UrlQuery.parseQueryDynamic: Type -> seq<string*string> -> obj
For example:
let pairs = ["foo","bar";"abc","[`xyz`,`123`]"]
let y = UrlQuery.parseQueryDynamic typeof<{|foo:string;abc:string[]|}> pairs
let z = box {|abc=[|"xyz";"123"|];foo="bar"|}
should.equal y z
JsonTree
The JsonTree
module is the module that operates Json
DU type.
This function reads the instance of the F# type as an instance of DU Json
type.
JsonTree.read: 't -> Json
For example:
let x = {|foo="bar";abc = ["xyz";"123"]|}
let y = JsonTree.read<{|foo:string;abc:string list|}> x
should.equal y
<| Json.Object ["abc",Json.Array [Json.String "xyz";Json.String "123"];"foo",Json.String "bar"]
This function JsonTree.write
converts the instance of DU Json type to an instance of the F# type.
JsonTree.write: Json -> 't
For example:
let json = Json.Object ["abc",Json.Array [Json.String "xyz";Json.String "123"];"foo",Json.String "bar"]
let y = JsonTree.write<{|foo:string;abc:string list|}> json
let z = {|foo="bar";abc = ["xyz";"123"]|}
should.equal y z
The function JsonTree.stringifyJson
serializes the instance of DU Json
type into a JSON string.
JsonTree.stringifyJson: Json -> string
For example:
let json = Json.Object ["abc",Json.Array [Json.String "xyz";Json.String "123"];"foo",Json.String "bar"]
let y = JsonTree.stringifyJson json
let z = """{"abc":["xyz","123"],"foo":"bar"}"""
should.equal y z
The function JsonTree.parseJson
parses the Json string to an instance of DU Json
type.
JsonTree.parseJson: string -> Json
For example:
let x = """{"abc":["xyz","123"],"foo":"bar"}"""
let y = JsonTree.parseJson x
let json = Json.Object ["abc",Json.Array [Json.String "xyz";Json.String "123"];"foo",Json.String "bar"]
should.equal y json
The function JsonTree.stringifyUrljson
serializes the instance of DU Json
type into an Urljson string.
JsonTree.stringifyUrljson: Json -> string
For example:
let json = Json.Object ["abc",Json.Array [Json.String "xyz";Json.String "123"];"foo",Json.String "bar"]
let y = JsonTree.stringifyUrljson json
let z = "{abc:[`xyz`,`123`],foo:`bar`}"
should.equal y z
The function JsonTree.parseUrljson
parses the Urljson string to an instance of DU Json
type.
JsonTree.parseUrljson: string -> Json
For example:
let x = "{abc:[`xyz`,`123`],foo:`bar`}"
let y = JsonTree.parseUrljson x
let json = Json.Object ["abc",Json.Array [Json.String "xyz";Json.String "123"];"foo",Json.String "bar"]
should.equal y json
ASP.NET
FSharpCompiler.Json
can be integrated into the ASP.NET as JSON's serialization library, Please use the library: AspNetCore.FSharpCompilerJson
。
see also
- The walkthrough tutorial is an ASP.NET solution that demonstrates how clients and servers serialize data.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- FSharp.Core (>= 6.0.1)
- FSharp.Idioms (>= 1.1.15)
- FSharp.Literals (>= 2.2.5)
- FslexFsyacc.Runtime (>= 1.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on FSharpCompiler.Json:
Package | Downloads |
---|---|
AspNetCore.FSharpCompilerJson
AspNetCore extensions to use FSharpCompiler.Json for serialization/deserialization. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
1.2.0 | 660 | 11/29/2021 | |
1.1.7 | 626 | 10/27/2021 | |
1.1.6 | 680 | 10/25/2021 | |
1.1.5 | 397 | 8/22/2021 | |
1.1.4 | 697 | 7/23/2021 | |
1.1.3 | 656 | 7/19/2021 | |
1.1.2 | 639 | 6/21/2021 | |
1.1.1 | 743 | 4/10/2021 | |
1.1.0 | 749 | 4/7/2021 | |
1.0.8 | 794 | 4/1/2021 | |
1.0.7 | 500 | 4/1/2021 | |
1.0.6 | 607 | 3/29/2021 | |
1.0.5 | 450 | 3/29/2021 | |
1.0.4 | 464 | 3/12/2021 | |
1.0.3 | 506 | 2/28/2021 | |
1.0.2 | 480 | 2/28/2021 | |
1.0.1 | 435 | 2/16/2021 | |
1.0.0 | 450 | 2/12/2021 |
migrate to FslexFsyacc