Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for nested json syntax #217

Merged
merged 24 commits into from
Jun 9, 2022
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift click to select a range
27a10f4
add support for nested json syntax
ducaale Dec 29, 2021
bdc95b3
handle edge cases in json_path parsing
ducaale Dec 30, 2021
22fff34
add tests for nested json syntax
ducaale Dec 30, 2021
438b0d1
pass raw_key to json_path parser
ducaale Dec 31, 2021
a803211
add some comments
ducaale Dec 31, 2021
f1466b1
handle edge cases when key contains unicode char
ducaale Dec 31, 2021
32c9434
update comment
ducaale Jan 4, 2022
d2eb5ba
Update to httpie's latest nested json spec
ducaale Jan 22, 2022
7f4bb3f
save surrounding bracket position in PathComponent
ducaale Feb 5, 2022
4244514
return an error on type clashes
ducaale Feb 5, 2022
6cc9d66
copy httpie's type clash error format
ducaale Feb 5, 2022
2e26982
add a bunch of todos
ducaale Feb 5, 2022
fcc1d13
fix an edge case in type clash error detection
ducaale Feb 12, 2022
585645b
construct error message for type clashes at root
ducaale Feb 12, 2022
b11dc2a
ban json_paths that start with [string]
ducaale Feb 12, 2022
61aaab8
improve errors in parse_path
ducaale Feb 27, 2022
c8317e2
add tests for type chashes and value overriding
ducaale Mar 1, 2022
3127deb
handle unicode chars when highlighting errors
ducaale Jun 6, 2022
34a74c2
test nested_json type error output
ducaale Jun 6, 2022
c890a8d
test keys that start with backslash and a number
ducaale Jun 6, 2022
4a1f787
reduce repetition in body_as_json()
ducaale Jun 6, 2022
fd15f96
rename `key` to `raw_key`
ducaale Jun 6, 2022
4a62b2d
link to httpie issue
ducaale Jun 9, 2022
bb4904d
test json path special chars escaping in --form
ducaale Jun 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update comment
  • Loading branch information
ducaale committed Feb 5, 2022
commit 32c943400616fbaaf075c7a03110095c5fde001d
14 changes: 6 additions & 8 deletions src/json_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 8,8 @@ use crate::utils::unescape;

/// Parse a JSON path.
///
/// A valid JSON path is either `ident([index]) ` or `([index])*`
/// where
/// - `index` -> string, number or empty
/// - `ident` -> string
/// A valid JSON path is either `text([index])*` or `([index]) ` where `index`
/// is `text`, `number` or `empty`.
///
/// Just like any `request_item`, special characters e.g `[` can be escaped with
/// a backslash character.
Expand Down Expand Up @@ -110,8 108,8 @@ pub fn set_value<T: AsRef<str>>(root: Value, path: &[T], value: Value) -> Value
let value = if path.len() == 1 {
value
} else {
let temp1 = remove_from_arr(&mut arr, index).unwrap_or(Value::Null);
set_value(temp1, &path[1..], value)
let temp = remove_from_arr(&mut arr, index).unwrap_or(Value::Null);
set_value(temp, &path[1..], value)
};
arr_append(&mut arr, index, value);
Value::Array(arr)
Expand All @@ -131,8 129,8 @@ pub fn set_value<T: AsRef<str>>(root: Value, path: &[T], value: Value) -> Value
let value = if path.len() == 1 {
value
} else {
let temp1 = obj.remove(path[0].as_ref()).unwrap_or(Value::Null);
set_value(temp1, &path[1..], value)
let temp = obj.remove(path[0].as_ref()).unwrap_or(Value::Null);
set_value(temp, &path[1..], value)
};
obj.insert("".to_string(), root);
obj.insert(path[0].as_ref().to_string(), value);
Expand Down