ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Fund Crystal's development: | GH: | Docs: | Gitter:
ur5us has quit [Ping timeout: 272 seconds]
ur5us has joined #crystal-lang
Sankalp has quit [Ping timeout: 240 seconds]
Sankalp has joined #crystal-lang
ur5us has quit [Ping timeout: 244 seconds]
ur5us has joined #crystal-lang
ur5us has quit [Remote host closed the connection]
ur5us has joined #crystal-lang
spuun has quit [Quit: brb.]
ur5us has quit [Ping timeout: 244 seconds]
sorcus has quit [Ping timeout: 248 seconds]
spuun has joined #crystal-lang
sorcus has joined #crystal-lang
Elouin has quit [Read error: Connection reset by peer]
Elouin has joined #crystal-lang
hellstabber has joined #crystal-lang
hellstabber has quit [Client Quit]
hellstabber has joined #crystal-lang
<frojnd> Hi there.
hellstabber has quit [Quit: Textual IRC Client:]
<frojnd> I'm trying to pass a json payload looks like this: `{"uploads":[{"name":"foo", "bar":["foo","bar"]}, {"name":"bar", "bar":["foo"]}]}` I'm using Kemal framework. Problem is that I don't know how to get further down uploads. How to catch params inside upload array. For uploads I do: uploads = env.params.json["uploads"].as(Array)
<frojnd> But how do I loop over name and bar?
<frojnd> Ok I'm inside uploads loop and elemts are of of type JSON::Any how can I parse so I can get to the name and bar?
<frojnd> Wow, just pp elemnt puted json string for each element! Nice
jmdaemon has quit [Ping timeout: 248 seconds]
<FromGitter> <Blacksmoke16> frojnd: you have two options
<FromGitter> <Blacksmoke16> 1) do what you're doing now and work with `JSON::Any`. E.g. to print the name of each obj you could do like: ⏎ ⏎ ```env.params.json["uploads"].as_a.each do |upload| ⏎ pp upload.as_h["name"].as_s ⏎ end``` []
<FromGitter> <Blacksmoke16> 2) define the structure of your payloads as structs and use, something like: ⏎ ⏎ ```uploads = Array(Upload).from_json env.request.body``` []
ur5us has joined #crystal-lang
wolfshappen has joined #crystal-lang
wolfshappen has quit [Quit: later]