Skip to content

Commit d6b8103

Browse files
authored
Review improvements (#9)
Add json_flatten separator overload Align json_flatten/json_add_prefix JSON flags with DuckDB JSONCommon Fix json_group_merge Combine correctness
1 parent 63cb6ab commit d6b8103

5 files changed

Lines changed: 485 additions & 67 deletions

File tree

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This extension provides a set of utility functions to work with JSON data, focus
1111

1212
## Core Features
1313

14-
- **`json_flatten(json)`**: Recursively flattens nested JSON objects and arrays into a single-level object with dot-separated keys.
14+
- **`json_flatten(json[, separator])`**: Recursively flattens nested JSON objects and arrays into a single-level object with path keys (default separator: `.`).
1515
- **`json_add_prefix(json, text)`**: Adds a string prefix to every top-level key in a JSON object.
1616
- **`json_group_merge(json [ORDER BY ...])`**: Streams JSON patches with RFC 7396 merge semantics without materializing intermediate lists.
1717

@@ -58,9 +58,20 @@ con.execute("LOAD './build/release/extension/json_tools/json_tools.duckdb_extens
5858

5959
## Usage
6060

61-
### `json_flatten(json) -> json`
61+
### `json_flatten(json[, separator]) -> json`
6262

63-
Rewrites nested JSON structures into a flat, dotted-key object. This is particularly useful for unnesting complex JSON for easier analysis.
63+
Rewrites nested JSON structures into a flat object with “path” keys. By default, path segments are joined with `.`.
64+
65+
You can pass an optional `separator` (a 1-character constant `VARCHAR`) to reduce the risk of ambiguous paths when your input keys contain `.`:
66+
```sql
67+
SELECT json_flatten('{"a.b": {"c": 1}}', '/');
68+
```
69+
*Result:*
70+
```json
71+
{"a.b/c":1}
72+
```
73+
74+
No escaping is performed: if your input keys contain the chosen `separator`, the output can be ambiguous and key collisions are possible. Behavior on collisions is not specified.
6475

6576
**Example:**
6677
```sql

0 commit comments

Comments
 (0)