How to return json-line or json-array format from API?

I want to use stream mode so the client to be able to display one object after the other without waiting for whole json object to be available.
Is there a way to control this? I tried all different ways but does not seem to work.

One idea is to make sure your root level is an array. a quick and dirty method would be to just append a ‘]’ after every token and see if it parses. if it does, update the ui! If you wanna be more sophisticated, you can look for ‘}’ or ‘},’ before trying a parse.

Is that what you mean?

Langchain’s JSON output parser supports streaming.

(*never tried it myself)