Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "json_diff_ng"
version = "0.3.1"
version = "0.4.0"
authors = ["ksceriath", "ChrisRega"]
edition = "2021"
license = "Unlicense"
Expand All @@ -25,7 +25,7 @@ path = "src/main.rs"
[dependencies]
thiserror = "1.0"
vg_errortools = "0.1"
serde_json = "1.0"
serde_json = { version = "1.0", features = ["preserve_order"] }
maplit = "1.0"
clap = {version = "4.4", features = ["derive"]}
diffs = "0.5"
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,3 @@ Currently, json-diff is available through crates.io (apart from building this re
`$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`
* Install json-diff
`$ cargo install json_diff`


14 changes: 2 additions & 12 deletions src/ds/key_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::collections::HashMap;
pub enum KeyNode {
Nil,
Value(Value, Value),
Array(Vec<(usize, KeyNode)>),
Node(HashMap<String, KeyNode>),
}

Expand Down Expand Up @@ -38,7 +37,7 @@ impl KeyNode {
let max_display_length = max_display_length.unwrap_or(4000);
let val_key = |key: Option<String>| {
key.map(|mut s| {
s.push_str(" ->");
s.push_str("->");
s
})
.unwrap_or_default()
Expand All @@ -58,16 +57,7 @@ impl KeyNode {
for (key, value) in map {
value.absolute_keys(
keys,
Some(format!("{} {}", val_key(key_from_root.clone()), key)),
Some(max_display_length),
)
}
}
KeyNode::Array(vec) => {
for (idx, value) in vec {
value.absolute_keys(
keys,
Some(format!("[l: {}] {}", idx, val_key(key_from_root.clone()))),
Some(format!("{}{}", val_key(key_from_root.clone()), key)),
Some(max_display_length),
)
}
Expand Down
6 changes: 6 additions & 0 deletions src/ds/mismatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ impl Mismatch {
}
}

pub fn is_empty(&self) -> bool {
self.left_only_keys == KeyNode::Nil
&& self.keys_in_both == KeyNode::Nil
&& self.right_only_keys == KeyNode::Nil
}

pub fn all_diffs(&self) -> Vec<(DiffType, ValueType)> {
self.all_diffs_trunc(None)
}
Expand Down
2 changes: 1 addition & 1 deletion src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Display for ValueType {
key,
value_right,
} => {
write!(f, "{key} {{ {value_left} != {value_right} }}")
write!(f, "{key}{{{value_left}!={value_right}}}")
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ struct Args {
#[command(subcommand)]
cmd: Mode,

#[clap(short, long)]
/// deep-sort arrays before comparing
sort_arrays: bool,

#[clap(short, long, default_value_t = 20)]
/// truncate keys with more chars then this parameter
truncation_length: usize,
Expand All @@ -36,7 +40,7 @@ fn main() -> Result<(), Error> {
}
};

let mismatch = compare_jsons(&json_1, &json_2)?;
let mismatch = compare_jsons(&json_1, &json_2, args.sort_arrays)?;

let comparison_result = check_diffs(mismatch)?;
if !comparison_result {
Expand Down
Loading