Skip to content

Instantly share code, notes, and snippets.

@sdogruyol
Created June 20, 2016 16:21
Show Gist options
  • Save sdogruyol/cce1a0b9cb39ae276112ce7e2e840a3d to your computer and use it in GitHub Desktop.
Save sdogruyol/cce1a0b9cb39ae276112ce7e2e840a3d to your computer and use it in GitHub Desktop.
require "kemal"
post "/json_params" do |env|
like_objects = env.params.json["_json"].as Array
like_objects.each do |likes|
likes_hash = (likes as Hash(String, JSON::Type))["likes"]
end
end
Kemal.run
@michaeldesu
Copy link

Thanks alot. For some reason, I had an error when I used "_json" (I'm not sure if that was a dummy variable). When I used a key value like below, it worked well. I appreciate you showing the way. I played around with it, and found making a temp variable with the casting made the result a bit more comfortable for me.

post "/" do |env|
    entry_elements = env.params.json["entry"] as Array
    entry_elements.each do |entries|
        e = entries as Hash(String, JSON::Type)
        id = e["id"]
        time = e["time"]
        puts id, time
    end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment