fsprojects / FSharp.Json

F# JSON Reflection based serialization library
Apache License 2.0
226 stars 26 forks source link

Support multidimensional arrays #18

Open dbarbashov opened 5 years ago

dbarbashov commented 5 years ago

For example,

let x : int[,] = Array2D.init 1 1 (fun _ _ -> 0)
vsapronov commented 5 years ago

I will add support for these shortly. Stay tuned.

vsapronov commented 5 years ago

@lkmfwe what are your thoughts regarding multidimensional arrays representation in JSON? How the should be represented in JSON? Currently I consider 2 options:

  1. Flat array of items
  2. Array of array of ... levels of nesting = number of dimensions
dbarbashov commented 5 years ago

I think 2nd option is more suitable, because its JSON has more information. Also, Newtonsoft.Json serializes multidimensional arrays exactly like that:

open Newtonsoft.Json

let x = JsonConvert.SerializeObject(Array2D.init 3 2 (fun i j -> (i+1)*(j+1)))
printfn "%s" x
// > "[[1,2],[2,4],[3,6]]"