From a9f8f0bf4be80b1ac5ec4f0ca830000c5f2cdee7 Mon Sep 17 00:00:00 2001 From: freestrings Date: Sat, 23 Mar 2019 11:51:35 +0900 Subject: [PATCH] =?UTF-8?q?select=5Fstr=20=EC=84=A4=EB=AA=85=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 16 ++++++---------- src/lib.rs | 17 +++++------------ src/ref_value/mod.rs | 3 +-- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 2364b1a..5fb2281 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,8 @@ It is an implementation of the `Rust` version [JsonPath] (https://goessner.net/articles/JsonPath/). `Webassembly` and` Javascript` also provide the same API interface. -## [Webassembly Demo](https://freestrings.github.io/jsonpath/) +- [Webassembly Demo](https://freestrings.github.io/jsonpath/) +- [Rust documentation](https://docs.rs/jsonpath_lib/0.1.6/jsonpath_lib) ## 왜? @@ -211,16 +212,11 @@ assert_eq!(json, ret) ### rust - jsonpath::select_str(json: &str, jsonpath: &str) ```rust -let json_obj = json!({ - "school": { - "friends": [{"id": 0}, {"id": 1}] - }, +let ret = jsonpath::select_str(r#"{ + "school": { "friends": [{"id": 0}, {"id": 1}] }, "friends": [{"id": 0}, {"id": 1}] -}); -let json_str = jsonpath::select_str(&serde_json::to_string(&json_obj).unwrap(), "$..friends[0]").unwrap(); -let json: Value = serde_json::from_str(&json_str).unwrap(); -let ret = json!([ {"id": 0}, {"id": 0} ]); -assert_eq!(json, ret) +}"#, "$..friends[0]").unwrap(); +assert_eq!(ret, r#"[{"id":0},{"id":0}]"#); ``` ### rust - jsonpath::compile(jsonpath: &str) diff --git a/src/lib.rs b/src/lib.rs index fd6592b..1503301 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -301,18 +301,11 @@ pub fn read(json: &Value, path: &str) -> Result { /// extern crate jsonpath_lib as jsonpath; /// #[macro_use] extern crate serde_json; /// -/// use serde_json::Value; -/// -/// let json_obj = json!({ -/// "school": { -/// "friends": [{"id": 0}, {"id": 1}] -/// }, -/// "friends": [{"id": 0}, {"id": 1}] -/// }); -/// let json_str = jsonpath::select_str(&serde_json::to_string(&json_obj).unwrap(), "$..friends[0]").unwrap(); -/// let json: Value = serde_json::from_str(&json_str).unwrap(); -/// let ret = json!([ {"id": 0}, {"id": 0} ]); -/// assert_eq!(json, ret); +/// let ret = jsonpath::select_str(r#"{ +/// "school": { "friends": [{"id": 0}, {"id": 1}] }, +/// "friends": [{"id": 0}, {"id": 1}] +/// }"#, "$..friends[0]").unwrap(); +/// assert_eq!(ret, r#"[{"id":0},{"id":0}]"#); /// ``` pub fn select_str(json: &str, path: &str) -> result::Result { let ref_value: RefValue = serde_json::from_str(json).map_err(|e| format!("{:?}", e))?; diff --git a/src/ref_value/mod.rs b/src/ref_value/mod.rs index 080642b..2c17c17 100644 --- a/src/ref_value/mod.rs +++ b/src/ref_value/mod.rs @@ -1,5 +1,4 @@ pub mod model; mod convert; pub mod de; -pub mod ser; -//mod utf8; \ No newline at end of file +pub mod ser; \ No newline at end of file