Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't decode a charlist #23

Closed
ndrean opened this issue Jul 28, 2023 · 4 comments
Closed

can't decode a charlist #23

ndrean opened this issue Jul 28, 2023 · 4 comments

Comments

@ndrean
Copy link

ndrean commented Jul 28, 2023

I receive a payload as a charlist from :httpc, so I need to convert it into a string to Jsonrs.decode! it. The library Jason can do it without the string conversion. Is it worth using Jsonrs when I have this kind of conversion to do?

@benhaney
Copy link
Owner

benhaney commented Jul 28, 2023

Good catch. I'll toss an IO.iodata_to_binary into decode! like Jason does.

@ndrean
Copy link
Author

ndrean commented Jul 30, 2023

You didn't push a new version, did you?

@benhaney
Copy link
Owner

benhaney commented Aug 4, 2023

I didn't cut a release to publish on Hex, no. I've been away for a few days and didn't want to release a new version for a small untested feature since I wouldn't be able to respond to any bugs it might cause.

Have you tried it out yet? Is it solving your problem and not causing any issues? I'll be happy to cut an official release if it seems to be working fine.

@ndrean
Copy link
Author

ndrean commented Aug 4, 2023

Probably only :httpc requires this addition since it uses charlist and not binary and outputs a charlist. Say you develop a package and want minimal dependencies and make small HTTP requests and decode the result, you may want this.

I believe a simple test in the terminal demonstrates it works

Mix.install([:jsonrs]);
{:ok, {{_, 200, _}, _, body}} = :httpc.request(:get, {~c"https://jsonplaceholder.typicode.com/posts", []},[], []);
to_string(body) |> Jsonrs.decode!

I only used Jsonrs when I query for npm packages, along with Finch (streaming this paginated endpoint) so it works as it is. If I add IO.iodata_to_binary() before decoding, it also works, so I believe it is ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants