bastienleonard has quit [Ping timeout: 244 seconds]
notzmv has quit [Ping timeout: 272 seconds]
sagax has joined #crystal-lang
notzmv has joined #crystal-lang
<FromGitter>
<galvertez> anybody know how to use `JSON::Builder` to intentionally build invalid json? i have a spec that requires invalid json and nothing i've tried works. would rather prefer to use the builder instead of just an ad-hoc string if possible
<FromGitter>
<galvertez> that feel when `JSON::Builder` is too good and won't let you do a bad
<FromGitter>
<Blacksmoke16> the trick is not using the block versions of the methods
rymiel has quit [Quit: quit]
rymiel has joined #crystal-lang
<FromGitter>
<moe:busyloop.net> for a spec i would rather embed invalid json as a string
<FromGitter>
<moe:busyloop.net> (easier to understand what's going on for older self or next-maintainer)
Stephie- is now known as Stephie
_ht has joined #crystal-lang
<FromGitter>
<galvertez> you might be right about that @moe:busyloop.net
<FromGitter>
<galvertez> just seems wonky because of how much of the API using a string bypasses
<FromGitter>
<galvertez> that being said, if i did just use a straight up string, the aspect in question would still satisfy the spec
<FromGitter>
<galvertez> but the test case is literally `it "handles an rpc call with invalid JSON" do` lol so i just made a helper class w/ a method `invalid_json`
<FromGitter>
<Blacksmoke16> you def can make invalid json with the builder, checkout the playground link
<FromGitter>
<galvertez> ya i saw - that should do everythign i need
<FromGitter>
<galvertez> thank you :D
<FromGitter>
<galvertez> i did something similar, except that i did it inside a class and defined `to_json(builder : JSON::Builder)` and it doesn't like that. i assume because of implicit usage of block versions of the methods
<FromGitter>
<galvertez> when calling `to_json` on the intance
<FromGitter>
<galvertez> sorry for a screenshot, but it's from my playground server on my homelab. i think i'm putting too much thought into this either way. i think moe is right. a string should suffice for this particular spec
<FromGitter>
<galvertez> doesn't matter if it's 1 char off or 1000, invalid json is invalid json.
<FromGitter>
<galvertez> so whether i `end_array` or just never close the object. it's still invalid
<FromGitter>
<galvertez> good enough for rock'n'roll
<FromGitter>
<Blacksmoke16> yea the builder is somewhat smart to prevent missing `{` and `]`, but shouldn't really matter
<FromGitter>
<Blacksmoke16> if you really wanted could prob just redefine `to_json : String` and return a scalar sting
<FromGitter>
<Blacksmoke16> string
Elouin has quit [Read error: Connection reset by peer]
Elouin has joined #crystal-lang
<FromGitter>
<galvertez> ya i actually wound up doing it w/ a plain io after i first posted just to get past it
<FromGitter>
<galvertez> also i gotta say. i just the other day got the playground up and running and i really like it a lot. haven't tried out the interpreter yet but the playground is really cool and does most of what i'd want out of an interpreter