toJson
Converts this DataFrame to a JSON array; each row becomes an element of that array.
By default, a row is written as a JSON object: a ColumnGroup becomes a nested object, a FrameColumn becomes a nested array of objects, and a List value becomes a JSON array.
There's one exception, so that a DataFrame read from JSON with a top-level type clash can be written back to its original form (see TypeClashTactic). Such a clash puts the elements that aren't objects into columns named "value" and "array", beside the objects' own properties. When one of the top-level columns is detected as such a "value" or "array" column — it's named "value" or "array" and only holds a value in rows where every other column holds none — a row is written as the record it was read from:
the value of the "value" column, if the row has one;
otherwise the array of the "array" column, if the row has one;
otherwise an object of the remaining columns, if any of them holds a value;
otherwise
null.
Only a top-level clash is restored like this:
A clash inside a
ColumnGroupisn't: the group is written as an object, so its "value" and "array" columns show up as ordinary properties.A single-column
DataFrameisn't either, since a lone "value"/"array" column is indistinguishable from one the user named that way. So a JSON array of non-objects, which is read into just a "value" or "array" column, doesn't round-trip:[1,2,3]is written back as[{"value":1},{"value":2},{"value":3}].
For more information: See the "value" and "array" columns on the documentation website.
Note too that some JSON records are read into the exact same DataFrame, so writing it back can only produce one of them: a row without any values is written as null, so [1,{"label":"record"},{"label":null}] becomes [1,{"label":"record"},null]; and an empty array of objects is read as an empty nested DataFrame, just like no array at all, so [{"label":"record"},[{"a":1}],[]] becomes [{"label":"record"},[{"a":1}],null].
Return
This DataFrame as a JSON string.
Parameters
Whether to format the output with indentation and line breaks. false by default.