Created
April 29, 2016 03:38
-
-
Save schmohlio/6c8b50816794615714d9a6b10fd432a2 to your computer and use it in GitHub Desktop.
flatten Json to arrays and primitive types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Newtonsoft.Json | |
let rec private _flattenJson (delim:string) (pkey:string) (json:JsonValue): (string * JsonValue) seq = | |
json.Properties | |
|> Seq.collect (fun (k, v) -> | |
match v with | |
| JsonValue.Record r -> _flattenJson delim k (JsonValue.Record r) | |
| _ -> [(pkey + delim + k, v)] |> Seq.ofList | |
) | |
/// flatten a Json nested children and stop at primitive or Array. specify delimiter for nested key names. | |
let flattenJson delimiter (json: JsonValue) = | |
_flattenJson delimiter "" json | |
|> Seq.map (fun (k, v) -> k, v.ToString()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment