Giter Club home page Giter Club logo

vitalbeats / newtonsoft.json.fsharp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from haf/newtonsoft.json.fsharp

0.0 4.0 0.0 557 KB

Nice F# support for Newtonsoft.JSON - tuples as arrays, maps as objects, lists as arrays, unions as _name-metadata annotated arrays, decimals as strings to save precision, options as null/value, string-GUIDs and finally BigInt support. **I recommend using Chiron https://github.com/xyncro/chiron instead of Newtonsoft**

Ruby 7.60% F# 92.40%

newtonsoft.json.fsharp's Introduction

Newtonsoft.Json.FSharp

Deprecated in favour of Chiron

Nice F# support for Newtonsoft.JSON - tuples as arrays, maps as objects, lists as arrays, unions as _name-metadata annotated arrays, decimals as strings to save precision, options as null/value, string-GUIDs and finally BigInt support.

Sponsored by qvitoo โ€“ A.I. bookkeeping.

Usage

You have three choices;

1. You can instantiate the converter:

open Newtonsoft.Json.FSharp
let str = JsonConvert.Serialize(o, [| GuidConverter() :> JsonConverter |])

2. You can add the converters:

open Newtonsoft.Json.FSharp
let str = JsonConvert.Serialize(o, Serialisation.converters)

3. You can extend JsonSerializerSettings with it

This is a nice way to do it, because you can then pass those settings into your Bootstrapper/Composition Root of your program. Remember you need to acutally use the settings.

open Newtonsoft.Json.FSharp
let opts = Serialisation.extend (JsonSerializerSettings()) // this goes global
let str = JsonConvert.Serialize(o, opts) // this is local

The Converters

You can find all the converters in the source tree.

The convert both from and to.

BigInt Converter

267321267876321I
=> {
  "_name": "System.Numeric.BigInt, System.Numeric"
  "value": "267321267876321"
}

CultureInfo Converter

CultureInfo "sv-SE"
=> "sv-SE"

Guid Converter

Guid.NewGuid()
=> "6ac5c744-ad0b-412c-bf11-9fb732344d90"

List Converter

[ 2;3;4;5 ]
=> [ 2,3,4,5 ]

Map Converter

[ "hello", "world"; "you", "there" ] => { "hello": "world", "you": "there" }

Option Converter

type A = { a : string; b : int option }
{ a = "hi"; b = None }
=> { "a": "hi", "b": null }

{ a = "hi"; b = Some 5 }
=>  { "a": "hi", "b": 5 }

Tuple Array Converter

"3", 4e11
=> [ "3", 4e11 ]

Union Converter

type Drinks =
  | Swimmingpool
  | IrishCoffee of teaSpoonsSugar:int
Swimmingpool
=> {
  "_name": "Drinks|Swimmingpool",
  "value": null
}

IrishCoffee 3
=> {
  "_name": "Drinks|IrishCoffee",
  "value": [ 3 ]
}

Uri Converter

Uri "http://haf.se"
=> "http://haf.se"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.