#827 Add implementation for the new JSON connector - #835
Conversation
ebhills
left a comment
There was a problem hiding this comment.
In you test examples your recipe looks like:
read:
json: ...
read / wrangles / write objects contain lists so each read / write must be a list element like:
read:
- json:
|
@ebhills, yes, the example description is not correct. I've fixed it. However, the implementation is ok. Please check for the 'test_write_json_basic' unit test to verify. |
@ebhills, yes, the example description is not correct. I've fixed it. However, the implementation is ok. Please check for the 'test_write_json_basic' unit test to verify.
|
@lmolotii - the test syntax is still wrong. Even if it works, I would prefer to document / test using the correct syntax. |
05c858a to
c7442db
Compare
2cc46bf to
62fe5cc
Compare
I've adjusted the tests to be compliant with the syntax remarks. Please check. |
|
@lmolotii we should add tests with multiple parameters used at the same time. Also, the massive amount of if statements seems a bit hacky. Would be nice to condense those in some way. |
|
I've added multiple tests to cover multi-parameter scenarios. However, I don't think that we can do something about multiple if's. Basically, there, we try to configure the pandas_kwargs, and if an argument is present, then we set the config in kwargs. How to avoid it, without adding the complexity for the implementation, is a good question. I had several options in mind:
But, it is just adds more code, without adding any value... I would prefer to keep it simple and in one place. |
|
I've updated the initialization of the pandas_kwargs. Please review it and let me know if you are ok with this approach. |
| date_unit: str = None, | ||
| encoding: str = None, | ||
| encoding_errors: str = 'strict', | ||
| lines: bool = None, |
There was a problem hiding this comment.
Users should not be allowed to set this parameter. This just opens the door for something like below, which there is no error handling for.
read:
- json:
name: tests/samples/data.json
lines: True| pandas_kwargs['orient'] = orient | ||
| else: | ||
| pandas_kwargs['orient'] = 'records' | ||
|
|
There was a problem hiding this comment.
Instead of setting so many parameters to None, lets just set them to the default in the first place. This will clean up all of the if statements, and also be much easier to quickly tell what the default is set to.
| """ | ||
| Test writing a basic .json file | ||
| """ | ||
| filename = f"tests/temp/{_uuid.uuid4()}.json" |
There was a problem hiding this comment.
The file connector uses a small handful of the same files to read and write, let's mimic that here. It just makes it easier to actually check the file being read/written if need be. For an example, see test_write_jsonl in test_file.py.
| df = df[columns] | ||
|
|
||
|
|
||
| path_matched = _re.search(r'^.+(?=\/\w+\.\w+)', name) |
There was a problem hiding this comment.
Please add comments where any ambiguity might exist, like here.
|
Queue triage (2026-07-27)
GitHub is the status record; update this PR rather than the external spreadsheet. |
JSON Connector specification
Overview
Implements the basic JSON connector that supports reading & writing JSON and JSONL (JSON Lines) files, it extends the existing implementation of the file connector, providing more options to configure the connector.
Usage Examples
Reading JSON Files
Reading JSONL Files
Using in Recipes
Writing JSON/JSONL Files
Explicit Connector Parameters
All parameters are explicitly documented and validated:
Read Parameters:
name- File path (required)columns- Subset of columns to readorient- JSON format ('split', 'records', 'index', 'columns', 'values')encoding- File encoding (default: 'utf-8')nrows- Number of rows to read (JSONL only!)lines- Whether file is line-delimited (auto-detected)compression- Compression type ('infer', 'gzip', 'bz2', 'zip', 'xz')Write Parameters:
name- File path (required)columns- Subset of columns to writeorient- JSON formatindent- Indentation level for pretty-printing (JSON only, not JSONL)lines- Write as line-delimited (auto-detected)compression- Compression type