Before you start
Prepare storage and a client connection using Read and write files. For the read example, save these two lines in an accessible.json file:
Read data
Use an explicit schema when fields must have stable types:(1, 12.5) and (2, 7.5). If the column list is omitted, the reader discovers a schema from a bounded sample. JSON does not accept the CSV/TSV inferSchema option.
Read a JSON document
For a formatted object or a top-level array of objects, setmultiLine 'true':
Write data
Use thespark connection from the shared file guide. The writer always produces JSON Lines, including when the input came from a JSON array.
mode("append") to add rows. SQL also supports a directory export:
Options
Use shared read options for paths, file filtering, and storage access. The writer has no configurable JSON format options. It does not accept
multiLine. Only uncompressed JSON output is supported.
Data types and limits
JSON field names map to columns. JSON numbers, booleans, strings, nulls, arrays, and objects are interpreted through the selected schema. An explicit schema avoids type changes caused by a different inference sample. Supported file suffixes are.json, .jsonl, and .ndjson. Match the suffix used by your input when setting pathGlobFilter. Header, delimiter, quote, and nullValue are not JSON options.
Row updates, deletes, and merges are not supported by this file sink. Use Iceberg or Delta Lake when those table operations are needed.