ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
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: www.textualapp.com]
<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``` [https://gitter.im/crystal-lang/crystal?at=62881ac5db6f627d259140be]
<FromGitter> <Blacksmoke16> 2) define the structure of your payloads as structs and use https://crystal-lang.org/api/JSON/Serializable.html, something like: ⏎ ⏎ ```uploads = Array(Upload).from_json env.request.body``` [https://gitter.im/crystal-lang/crystal?at=62881affef00bd1dc6ef4758]
ur5us has joined #crystal-lang
wolfshappen has joined #crystal-lang
wolfshappen has quit [Quit: later]