Solved: How to iterize over JSON values?

Is it possible to iterize over JSON keys like with hash.each_key?

Would have to do json.as_h.each_key.

Unfortunately that does not work:

In json_test1.cr:45:16

 45 | items["rates"].to_h.each_key do |k|
                     ^---
Error: undefined method 'to_h' for JSON::Any

It’s as_h not to_h.

See https://crystal-lang.org/api/JSON/Any.html#as_h:Hash(String,Any)-instance-method.

1 Like

Yes, that works, reading is difficult :frowning:
Thanks @Blacksmoke16!