Shell/RPC: allow immediate value
This a HACK for allowing serialisation of toplevel value that are float, string,... and not only object or array. In a latter time, we may prefer to you `yojson` instead of `ezjsonm`, but some of our dependencies rely on `ezjsonm` and we may not want to embeds two distinct JSON libraries...
This commit is contained in:
parent
556e95cef0
commit
cf9d26740c
@ -274,13 +274,16 @@ let to_root = function
|
|||||||
| `Null -> `O []
|
| `Null -> `O []
|
||||||
| oth -> `A [ oth ]
|
| oth -> `A [ oth ]
|
||||||
|
|
||||||
let to_string ?minify j = Ezjsonm.to_string ?minify (to_root j)
|
let to_string ?minify j =
|
||||||
|
Format.asprintf "%a" Json_repr.(pp ?compact:minify (module Ezjsonm)) j
|
||||||
|
|
||||||
let pp = Json_repr.(pp (module Ezjsonm))
|
let pp = Json_repr.(pp (module Ezjsonm))
|
||||||
|
|
||||||
let from_string s =
|
let from_string s =
|
||||||
try Ok (Ezjsonm.from_string s :> json)
|
match Ezjsonm.from_string ("[" ^ s ^ "]") with
|
||||||
with Ezjsonm.Parse_error (_, msg) -> Error msg
|
| exception Ezjsonm.Parse_error (_, msg) -> Error msg
|
||||||
|
| `A [ json ] -> Ok json
|
||||||
|
| _ -> Error "Malformed value"
|
||||||
|
|
||||||
let from_stream (stream: string Lwt_stream.t) =
|
let from_stream (stream: string Lwt_stream.t) =
|
||||||
let buffer = ref "" in
|
let buffer = ref "" in
|
||||||
|
Loading…
Reference in New Issue
Block a user