writeJSON is not writing valid json
Closed this issue · 2 comments
apetta commented
Have you tried latest version of polars?
- [yes]
What version of polars are you using?
0.14.0
What operating system are you using polars on?
MacOS
What node version are you using
18.18.2
Describe your bug.
A dataframe exported as JSON is missing the top-level array & commas. It just exports something like:
{"id":"group:1","key":"a"}
{"id":"group:2","key":"b"}
{"id":"group:3","key":"c"}
{"id":"group:4","key":"d"}
What are the steps to reproduce the behavior?
Make a dataframe and export it to json
Example
import pl from "nodejs-polars";
// Create a simple dataset on which we can reproduce the bug.
pl.DataFrame({
foo: [1, 1, 2],
bar: [1n, 2n, 3n],
}).writeJSON("test.json");
What is the actual behavior?
Show the query you ran and the actual output.
If the output is large, put it in a gist: https://gist.github.com/
If the output is small, put it in code fences:
{"foo":1.0,"bar":1}
{"foo":1.0,"bar":2}
{"foo":2.0,"bar":3}
What is the expected behavior?
[
{ "foo": 1.0, "bar": 1 },
{ "foo": 1.0, "bar": 2 },
{ "foo": 2.0, "bar": 3 }
]
universalmind303 commented
@apetta this is a valid json format called ndjson/json-lines.
It's generally much more performant than the standard json format.
We also support standard json.
https://pola-rs.github.io/nodejs-polars/interfaces/pl.DataFrame-1.html#writeJSON
apetta commented
@universalmind303 my bad for not reading the docs properly, thank you!