I have a JSON response which is an Array of Hash:
[{"project" => {"id" => 1, "name" => "Internal"},
{"project" => {"id" => 2, "name" => "External"}}]
My code looks like this:
client = HTTP::Client.new(url, ssl: true)
response = client.get("/projects", ssl: true)
projects = JSON.parse(response.body) as Array
This gives me an Array but it seems I need to typecast the elements to actually use them otherwise I get undefined method '[]' for Nil (compile-time type is (Nil | String | Int64 | Float64 | Bool | Hash(String, JSON::Type) | Array(JSON::Type)))
.
I tried as Array(Hash)
but this gives me can't use Hash(K, V) as generic type argument yet, use a more specific type
.
How do I specify the type?