<< 08-09-2024 >>

00:01:04*beholders_eye joined #nim
00:16:17FromDiscord<sirius_3x> how do I convert a tuple into a JSON object?
00:17:34FromDiscord<sirius_3x> (edit) "object?" => "object string? is there any built-in function for that?↵I already tried $ and % but they output something like this:↵"(name: \"Alice\", age: 30, isStudent: false, skills: [\"nim\", \"python\", \"cpp\"])""
00:19:15FromDiscord<sirius_3x> sent a long message, see https://pasty.ee/ZRXGtRHK
00:19:53FromDiscord<sirius_3x> (edit) "long message," => "code paste," | "https://pasty.ee/QCoPlrRB" => "https://play.nim-lang.org/#pasty=OjJGXYWK"
00:20:48FromDiscord<Elegantbeef> `%(bleh).pretty`
00:26:14FromDiscord<sirius_3x> In reply to @Elegantbeef "`%(bleh).pretty`": ty for the quick response but %() doesnt seem to work on tuples, is that right?
00:27:58FromDiscord<sirius_3x> sent a code paste, see https://play.nim-lang.org/#pasty=OwdmBxSY
00:28:11FromDiscord<sirius_3x> (edit) "https://play.nim-lang.org/#pasty=QAVmtntA" => "https://play.nim-lang.org/#pasty=ldnjkAZy"
00:28:44FromDiscord<sirius_3x> With or without pretty
00:29:54*lucasta quit (Remote host closed the connection)
00:30:31FromDiscord<Elegantbeef> Guess you need `%`
00:30:40FromDiscord<Elegantbeef> I do not recall these asinine operators
00:30:45FromDiscord<sirius_3x> xD
00:31:02FromDiscord<sirius_3x> In reply to @Elegantbeef "Guess you need `%*`": still doesnt seem to work though :/
00:31:11FromDiscord<sirius_3x> any third party library you can recommend?
00:33:01FromDiscord<sirius_3x> nvm think I mightve found one, ty for your help btw
00:33:28FromDiscord<Elegantbeef> You can just write the `%` for a tuple
00:34:57FromDiscord<sirius_3x> sent a code paste, see https://play.nim-lang.org/#pasty=xwHhRJul
00:35:02FromDiscord<sirius_3x> In reply to @Elegantbeef "You can just write": throws an error
00:35:17FromDiscord<sirius_3x> (edit) "https://play.nim-lang.org/#pasty=bJykBraO" => "https://play.nim-lang.org/#pasty=WSaapVAz"
00:35:59FromDiscord<sirius_3x> unless I convert it to a string first, via $, but that kinda defeats the purpose
00:37:54FromDiscord<Robyn [She/Her]> In reply to @sirius_3x "any third party library": jsony and sunny are good
00:38:12FromDiscord<Elegantbeef> Neither do pretty json though
00:38:58FromDiscord<Robyn [She/Her]> In reply to @Elegantbeef "Neither do pretty json": you can convert to a JsonNode
00:39:28FromDiscord<Elegantbeef> So bring in a dependency for no reason
00:39:30FromDiscord<Robyn [She/Her]> `fromJson(JsonNode, myTup.toJson())`, iirc
00:39:35FromDiscord<Robyn [She/Her]> In reply to @Elegantbeef "So bring in a": shrug
00:42:54FromDiscord<Elegantbeef> Heh not only bringing in a dependency but converting to a json string then parsing back to a json node to then store as a json string
00:42:56FromDiscord<Elegantbeef> Steps for days
00:45:33*beholders_eye quit (Read error: Connection reset by peer)
00:46:23FromDiscord<sirius_3x> sent a code paste, see https://play.nim-lang.org/#pasty=ApbMPzfE
00:46:55FromDiscord<sirius_3x> (edit) "https://play.nim-lang.org/#pasty=kJmujHtl" => "https://play.nim-lang.org/#pasty=vwvNpVHH"
00:47:12FromDiscord<Elegantbeef> I jusut showed you how
00:47:15FromDiscord<Elegantbeef> just\
00:47:25FromDiscord<Elegantbeef> Bridge moment
00:47:37FromDiscord<Elegantbeef> https://play.nim-lang.org/#pasty=CEJqVMSr
00:47:44FromDiscord<Elegantbeef> What a bridge
00:51:22*beholders_eye joined #nim
00:52:14FromDiscord<sirius_3x> Thanks, that code does actually work! However, if I omit the proc that you copied from stdlib, it doesnt work. Idk why. I thought this function is part of the std library? Doesn't it get imported for some reason?↵The other thing is, your original answer actually had the % outside of the brackets, thats why it also wouldnt work
00:52:36FromDiscord<Elegantbeef> The stdlib's `%` for whatever reason does not work with tuples
00:52:51FromDiscord<sirius_3x> In reply to @Elegantbeef "The stdlib's `%` for": so you did actually just write a custom function for that lmao
00:53:08FromDiscord<Elegantbeef> Well I stole the stdlib's object code
00:53:11FromDiscord<Elegantbeef> Since it's the same thing
00:53:54FromDiscord<Elegantbeef> Operators bind to the entire expression not the first part
00:54:10FromDiscord<Elegantbeef> so `$bleh[0].meh.huh` is `$(bleh[0].meh.huh)`
00:54:10FromDiscord<Robyn [She/Her]> In reply to @Elegantbeef "Well I stole the": using fieldPairs on a named tuple?
00:54:24FromDiscord<Elegantbeef> You can use it on all tuples
00:54:31FromDiscord<sirius_3x> In reply to @Elegantbeef "Well I stole the": oh true, smart actually, lol↵thanks again
00:54:32FromDiscord<Elegantbeef> Doesn't matter if it's named or unnamed
00:54:38FromDiscord<Elegantbeef> If it's unnamed you get `Field0`....
00:54:42FromDiscord<Robyn [She/Her]> In reply to @Elegantbeef "You can use it": oh?
00:54:47FromDiscord<Robyn [She/Her]> In reply to @Elegantbeef "If it's unnamed you": damn, neat
00:56:50*beholders_eye quit (Ping timeout: 252 seconds)
01:00:06*albe4 joined #nim
01:01:37FromDiscord<nervecenter> In reply to @sirius_3x "are you sure? Because": If there's a way to convert a tuple to a seq first that might be a good middle ground
01:02:16FromDiscord<Elegantbeef> tuple to a seq.... that only works if the tuple is singly typed
01:02:18*albe quit (Ping timeout: 244 seconds)
01:02:19*albe4 is now known as albe
01:03:52FromDiscord<sirius_3x> In reply to @nervecenter "If there's a way": Elegantbeef also already kindly provided a function that converts any tuple to a JSONobject
01:04:50FromDiscord<nervecenter> In reply to @Elegantbeef "tuple to a seq....": right, dang forgot about that
01:05:28FromDiscord<nervecenter> yeah beef's proc is exactly what I would do given the constraints
01:05:47FromDiscord<nervecenter> iterate over the values and drop them in a new JArray
01:05:52FromDiscord<Elegantbeef> It's what the stdlib should do `T: object | tuple` instead of just `T: object`
01:06:10FromDiscord<Elegantbeef> You also misread their goal nerve
01:06:17FromDiscord<Elegantbeef> They want to have a prettified json object
01:06:48FromDiscord<nervecenter> Oh I see it's a named tuple
01:06:55FromDiscord<nervecenter> please ignore me I am not thinking atm
01:15:34FromDiscord<sirius_3x> In reply to @Elegantbeef "It's what the stdlib": beef, are you creating a pull request for that? cause if not then I will
01:35:46FromDiscord<sirius_3x> In reply to @Elegantbeef "It's what the stdlib": nvm I just created one and made sure to credit you in the description, in case thats important to you. hope you dont mind.
03:16:30*xutaxkamay quit (Quit: ZNC 1.8.2+deb3.1+deb12u1 - https://znc.in)
03:16:40*xutaxkamay_ joined #nim
03:17:29*xutaxkamay_ is now known as xutaxkamay
03:53:40*SchweinD1 quit (Quit: WeeChat 4.5.0-dev)
03:54:24*SchweinDeBurg joined #nim
05:10:09*albe quit (Quit: The Lounge - https://thelounge.chat)
05:10:32*albe joined #nim
06:10:32*coldfeet joined #nim
06:36:01*xet7 quit (Ping timeout: 272 seconds)
07:00:11*ntat joined #nim