Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abrarnitk/sorted_json_keys
Small Rust library to filter and sort the json.
https://github.com/abrarnitk/sorted_json_keys
Last synced: 22 days ago
JSON representation
Small Rust library to filter and sort the json.
- Host: GitHub
- URL: https://github.com/abrarnitk/sorted_json_keys
- Owner: AbrarNitk
- License: mit
- Created: 2019-03-05T20:31:23.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-11-20T12:49:27.000Z (about 2 months ago)
- Last Synced: 2024-11-20T13:27:19.118Z (about 2 months ago)
- Language: Rust
- Homepage:
- Size: 15.6 KB
- Stars: 1
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sorted_json_keys
Rust lib to sort JSON based on string keys and filter json values
Note:
- filter is working based on the keys
- sorted is buggy, need improvements```rust
#[cfg(test)]
mod tests {
use crate::filter::keys::filter;
#[test]
fn test_map_filter() {
let data: serde_json::Value = serde_json::json!({
"foo": "bar",
"config": {
"foo-config": "bar",
"temp": "temppp",
"hector": "tractor"
}
});let filtered = filter(data, &|key| {
vec!["foo", "config.temp", "config.hector"].contains(&key)
});let expected = serde_json::json!({
"config": {
"hector": "tractor",
"temp": "temppp"
},
"foo": "bar"
});assert_eq!(expected, filtered);
// println!("value: {}", serde_json::to_string_pretty(&value).unwrap());
}#[test]
fn test_list_filter() {
let data: serde_json::Value = serde_json::json!({
"foo": "bar",
"config": [
{
"foo-config": "bar",
"temp": "temppp",
"hector": "tractor"
},
{
"foo-config": "bar1",
"temp": "temppp1",
"hector": "tractor1"
}
]
});let expected = serde_json::json!({
"foo": "bar",
"config": [
{
"hector": "tractor",
"temp": "temppp"
},
{
"hector": "tractor1",
"temp": "temppp1"
}
]
});let filtered = filter(data, &|key| {
vec!["foo", "config.[].temp", "config.[].hector"].contains(&key)
});
assert_eq!(expected, filtered);
}#[test]
fn filter_inner_list() {
let data: serde_json::Value = serde_json::json!({
"foo": "bar",
"config": [
{
"foo-config": "bar",
"temp": [{ "a": 1 }],
"hector": "tractor"
},
{
"foo-config": "bar1",
"temp": [{ "a": 2 }],
"hector": "tractor1"
}
]
});let filtered = filter(data, &|key| key == "config.[].temp.[].a");
let expected: serde_json::Value = serde_json::json!({
"config": [
{
"temp": [{ "a": 1 }],
},
{
"temp": [{ "a": 2 }],
}
]
});assert_eq!(expected, filtered);
// println!("value: {}", serde_json::to_string_pretty(&filtered).unwrap());
}
}```