Skip to content

Commit

Permalink
Merge pull request #177 from itchyny/implement-pick
Browse files Browse the repository at this point in the history
Implement pick/1 filter
  • Loading branch information
MiSawa authored Feb 25, 2024
2 parents d8f28b4 + 656918f commit 1a37b3d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions prelude.jq
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def nth($n): .[$n];

def del(f): delpaths([path(f)]);
def setpath($paths; $v): getpath($paths) |= $v;
def pick(f): . as $v | reduce path(f) as $p (null; setpath($p; $v | getpath($p)));

def to_entries: [keys[] as $key | {$key, value: .[$key]}];
def from_entries: reduce .[] as $entry ({}; .[$entry.key]=$entry.value);
Expand Down
13 changes: 13 additions & 0 deletions tests/from_manual/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,19 @@ test!(
"#
);

test!(
pick1,
r#"
pick(.x, .y[2], .y[0], .z)
"#,
r#"
{"x":1,"y":[1,2,3]}
"#,
r#"
{"x":1,"y":[1,null,3],"z":null}
"#
);

test!(
entries1,
r#"
Expand Down

0 comments on commit 1a37b3d

Please sign in to comment.