Skip to content

Instantly share code, notes, and snippets.

@ellcs
Last active June 11, 2020 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ellcs/a957cf4a1c0dc51d9221076bf96e2012 to your computer and use it in GitHub Desktop.
Save ellcs/a957cf4a1c0dc51d9221076bf96e2012 to your computer and use it in GitHub Desktop.
# https://crystal-lang.org/api/0.22.0/JSON.html
# online repl: https://play.crystal-lang.org/#/r/995s
require "json"
value = JSON.parse("[1, 2, 3]").raw # : JSON::Any
# (Array(JSON::Any) | Bool | Float64 | Hash(String, JSON::Any) | Int64 | String | Nil)
typeof(value)
if value.is_a?(Array)
puts typeof(value) # Array(JSON::Any)
elsif value.is_a?(Hash)
puts typeof(value) # Hash(JSON::Any)
elsif value.is_a?(Int64)
puts "int"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment