FSharpCompiler.Json 1.1.6

Suggested Alternatives

UnquotedJson

Additional Details

The new package implements all the features of this package and has a better API.

There is a newer version of this package available.
See the version list below for details.
dotnet add package FSharpCompiler.Json --version 1.1.6                
NuGet\Install-Package FSharpCompiler.Json -Version 1.1.6                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FSharpCompiler.Json" Version="1.1.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FSharpCompiler.Json --version 1.1.6                
#r "nuget: FSharpCompiler.Json, 1.1.6"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install FSharpCompiler.Json as a Cake Addin
#addin nuget:?package=FSharpCompiler.Json&version=1.1.6

// Install FSharpCompiler.Json as a Cake Tool
#tool nuget:?package=FSharpCompiler.Json&version=1.1.6                

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

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

update compiler translation