Questions tagged [bs-json]

Use for questions relating to the bs-json BuckleScript library, always along with the [bucklescript] tag and optionally with [json]. Use [ocaml] or [reason] depending on the syntax used.

bs-json is a library for encoding and decoding . Usually used with or .

9 questions
4
votes
1 answer

Using bs-json to Decode object with dynamic keys in root

I am trying to decode the following JSON object into a Reason object. {"AAPL":{"price":217.36}} The key in the root of the object is dynamic. The following general example works when the key is not in the root. How would I change it so it works for…
Sepehr Sobhani
  • 862
  • 3
  • 12
  • 29
3
votes
1 answer

What does Json.Decode.{} mean? The dot curly braces part

I'm trying to learn ReasonML and following the example for bs-json we can decode raw json into a type like this: type point = { x: float, y: float }; module Decode = { let point = json => Json.Decode.{ x: json |> field("x",…
Homan
  • 25,618
  • 22
  • 70
  • 107
3
votes
2 answers

Convert JSON field to ReasonML variant

I have a JSON structure that contains a field period that can either be an object or a string. I already have the variant ready in my code, and it's working fine: type period = { start: string, end_: string, }; type periodVariant = |…
Bertrand
  • 1,718
  • 2
  • 13
  • 24
2
votes
1 answer

How to read JSON with unknown key in ReasonML?

I am writing a simple application that display dog images from Dog API. I used bs-json to make it a record and use it later. The list of breeds can be obtained by the API. The response looks like this. { "message": { "breed": ["array of…
1
vote
1 answer

How to convert Js.Json.t to Js.t('a)?

I have encoded an object via bs-json and want to send it as a data via post using bs-axios. 33 │ let createTest = (p: Data.toBuyListItem) => inst->Instance.postData("/ test", p |> Data.encodeToBuyListItem); ... This has type: …
menfon
  • 1,587
  • 1
  • 11
  • 28
1
vote
2 answers

How to decode GeoJson in ReasonML?

Please comment how to decode a GeoJson file in ReasonML? I try to decode coordinates without "field latitude & longitude" in decoder, but I cannot find any information how to parse the field coordinates in the JSON file. GeoJson file "features":…
madeinQuant
  • 1,721
  • 1
  • 18
  • 29
0
votes
1 answer

Trying to decode an event using rescript-json-combinators

Trying to create an equivalent for decodeEvent using rescript-json-combinators. I couldn't figure out how to replace "Decoder(decoder)" since Decoders have been made abstract in rescript-json-combinators. Trying to use Decode.decode didn't work. Any…
Fer iel
  • 23
  • 4
0
votes
0 answers

How can decode similar JSON structures?

I'm using @glennsl's bs-json module to decode some JSON responses, but all the JSON responses have some common fields in addition to their unique payload. Furthermore, the JSON responses (via XMLHTTPRequest) are different depending on whether…
Jamie
  • 7,075
  • 12
  • 56
  • 86
0
votes
1 answer

Is there a way to encode integer values that are larger than 32 bits using bs-json?

I've been using strings to represent decoded JSON integers larger than 32 bits. It seems the string_of_int is capable of dealing with large integer inputs. So a decoder, written (in the Json.Decode namespace): id: json |> field("id", int) |>…
Jamie
  • 7,075
  • 12
  • 56
  • 86