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

Add a json_encode #85

Open
Neirda24 opened this issue Jun 13, 2021 · 2 comments
Open

Add a json_encode #85

Neirda24 opened this issue Jun 13, 2021 · 2 comments

Comments

@Neirda24
Copy link

I don't know if it would be relevant or not. Some benchmark might be required to determine whether or not the original json_encode would fail on big arrays with big objects. If so using iterators could become useful. Comparing to the original one there would be the need for special const such as FORCE_OBJECT(which already exists) and a FORCE_LIST

@nikic
Copy link
Owner

nikic commented Jun 13, 2021

I think this would be out of scope. Effectively this calls for a streaming JSON encoder, as you'd probably want not just the input to be an iterator, but the output to be incremental as well. A quick google turns up https://github.com/violet-php/streaming-json-encoder, though I have no further familiarity with that library.

@Neirda24
Copy link
Author

Thank you for this library. I was not talking about streaming per se (Already did something using the StreamResponse + IteratorAgreggate + __invoke) but rather a generic iterable->toJsonString taht we could then store for example in a database or else. I don't know if there are usecase where json_encode(iterator_to_array($myIterator)) would create a massive overhead in memory that we could avoid with this new function.

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