2

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 sub-breeds"],
  "breed without subbreed": [],
  ...
  },
"status": "success"
}

So the key is not known at the compile time. If I add it one by one, it would be some kind of hardcode. I only want breeds not sub-breeds. If possible, I would like an array of them.

[| "chihuahua", "golden retreiver", ... |] // Something like this so I can make a select input
glennsl
  • 28,186
  • 12
  • 57
  • 75

1 Answers1

1

I think you could just decode into a Js.Dict.t and then take its keys.

Something like:

let decodeBreeds: Js.Json.t => array(string) =
  Json.Decode.(dict(id) |> map(Js.Dict.keys))
glennsl
  • 28,186
  • 12
  • 57
  • 75