Skip to content

Commit de1efb1

Browse files
committed
Document --from-gron
1 parent dc60f65 commit de1efb1

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

docs/manual.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ This file contains the simplified response from the Yahoo Finance Unofficial JSO
150150
* [Pretty Printing](#pretty-printing)
151151
* [Raw Output](#raw-output)
152152
* [Grep friendly output](#grep-friendly-output)
153+
* [Reverting filtered grep output](#reverting-filtered-grep-output)
153154

154155
### Reading Files
155156

@@ -475,6 +476,40 @@ json.bin[0].path = "src/main.rs";
475476

476477
If you need deterministic outputs, we recommend using the `-S` flag for sorting the output.
477478

479+
### Reverting filtered grep output
480+
481+
`celq` also has a `--from-gron` flag that parsers the output of `gron` and `celq --greppable`. It is equivalent to `gron -u`. That can be useful for converting output filtered by grep back to JSON.
482+
483+
For example:
484+
485+
```bash
486+
celq -g 'this' < yfinance.json | rg '\bregularMarket\w*' | celq --from-gron -S -p 'this'
487+
```
488+
489+
Outputs:
490+
491+
<details>
492+
<summary>ripgrep output back to JSON</summary>
493+
494+
```json
495+
{
496+
"chart": {
497+
"result": [
498+
{
499+
"meta": {
500+
"regularMarketDayHigh": 277.825,
501+
"regularMarketDayLow": 269.02,
502+
"regularMarketPrice": 271.01,
503+
"regularMarketTime": 1767387600
504+
}
505+
}
506+
]
507+
}
508+
}
509+
```
510+
511+
</details>
512+
478513
## Quirks
479514

480515
1. Do not rely on the order of the JSON output, by default it is randomized due to Rust implementation details. If you need ordering, pass `--sort-keys` as an argument

src/ungron.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ fn parse_and_apply_line(line: &str, root: &mut JsonValue) -> Result<()> {
3232
set_value_at_path(root, &path, value)?;
3333
Ok(())
3434
} else {
35-
// gron occasionally emits 'const' or 'var' depending on flags,
36-
// but standard gron is pure assignment.
3735
Err(anyhow!("Expected assignment (e.g., json.a = 1)"))
3836
}
3937
}
@@ -139,7 +137,7 @@ fn set_value_at_path(root: &mut JsonValue, path: &[PathSegment], value: JsonValu
139137
}
140138
}
141139

142-
// Logic Fix: Don't overwrite an existing object/array with an empty one.
140+
// Don't overwrite an existing object/array with an empty one.
143141
if (value.is_object() && value.as_object().unwrap().is_empty() && cur.is_object())
144142
|| (value.is_array() && value.as_array().unwrap().is_empty() && cur.is_array())
145143
{

0 commit comments

Comments
 (0)