mirror of
https://github.com/fluencelabs/jsonpath
synced 2025-04-25 09:22:19 +00:00
version 0.1.1 - travis-ci 적용
This commit is contained in:
parent
577b6377f9
commit
cd01540d75
84
.travis.yml
Normal file
84
.travis.yml
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
language: rust
|
||||||
|
sudo: false
|
||||||
|
|
||||||
|
cache: cargo
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
|
||||||
|
- rust: stable
|
||||||
|
env: RUST_BACKTRACE=1
|
||||||
|
# addons:
|
||||||
|
# firefox: latest
|
||||||
|
# chrome: stable
|
||||||
|
before_script:
|
||||||
|
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
|
||||||
|
- (test -x $HOME/.cargo/bin/cargo-generate || cargo install --vers "^0.2" cargo-generate)
|
||||||
|
- cargo install-update -a
|
||||||
|
- curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -f
|
||||||
|
script:
|
||||||
|
- cargo build --verbose --all
|
||||||
|
- cargo test --verbose --all
|
||||||
|
- cd wasm
|
||||||
|
- wasm-pack build
|
||||||
|
# - wasm-pack test --chrome --firefox --headless
|
||||||
|
|
||||||
|
# Builds with wasm-pack.
|
||||||
|
- rust: beta
|
||||||
|
env: RUST_BACKTRACE=1
|
||||||
|
# addons:
|
||||||
|
# firefox: latest
|
||||||
|
# chrome: stable
|
||||||
|
before_script:
|
||||||
|
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
|
||||||
|
- (test -x $HOME/.cargo/bin/cargo-generate || cargo install --vers "^0.2" cargo-generate)
|
||||||
|
- cargo install-update -a
|
||||||
|
- curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -f
|
||||||
|
script:
|
||||||
|
- cargo build --verbose --all
|
||||||
|
- cargo test --verbose --all
|
||||||
|
- cd wasm
|
||||||
|
- wasm-pack build
|
||||||
|
# - wasm-pack test --chrome --firefox --headless
|
||||||
|
|
||||||
|
# Builds on nightly.
|
||||||
|
- rust: nightly
|
||||||
|
env: RUST_BACKTRACE=1
|
||||||
|
before_script:
|
||||||
|
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
|
||||||
|
- (test -x $HOME/.cargo/bin/cargo-generate || cargo install --vers "^0.2" cargo-generate)
|
||||||
|
- cargo install-update -a
|
||||||
|
- rustup target add wasm32-unknown-unknown
|
||||||
|
script:
|
||||||
|
- cargo build --verbose --all
|
||||||
|
- cargo test --verbose --all
|
||||||
|
- cd wasm
|
||||||
|
- cargo check
|
||||||
|
- cargo check --target wasm32-unknown-unknown
|
||||||
|
- cargo check --no-default-features
|
||||||
|
- cargo check --target wasm32-unknown-unknown --no-default-features
|
||||||
|
- cargo check --no-default-features --features console_error_panic_hook
|
||||||
|
- cargo check --target wasm32-unknown-unknown --no-default-features --features console_error_panic_hook
|
||||||
|
- cargo check --no-default-features --features "console_error_panic_hook wee_alloc"
|
||||||
|
- cargo check --target wasm32-unknown-unknown --no-default-features --features "console_error_panic_hook wee_alloc"
|
||||||
|
|
||||||
|
# Builds on beta.
|
||||||
|
- rust: beta
|
||||||
|
env: RUST_BACKTRACE=1
|
||||||
|
before_script:
|
||||||
|
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
|
||||||
|
- (test -x $HOME/.cargo/bin/cargo-generate || cargo install --vers "^0.2" cargo-generate)
|
||||||
|
- cargo install-update -a
|
||||||
|
- rustup target add wasm32-unknown-unknown
|
||||||
|
script:
|
||||||
|
- cargo build --verbose --all
|
||||||
|
- cargo test --verbose --all
|
||||||
|
- cd wasm
|
||||||
|
- cargo check
|
||||||
|
- cargo check --target wasm32-unknown-unknown
|
||||||
|
- cargo check --no-default-features
|
||||||
|
- cargo check --target wasm32-unknown-unknown --no-default-features
|
||||||
|
- cargo check --no-default-features --features console_error_panic_hook
|
||||||
|
- cargo check --target wasm32-unknown-unknown --no-default-features --features console_error_panic_hook
|
||||||
|
# Note: no enabling the `wee_alloc` feature here because it requires
|
||||||
|
# nightly for now.
|
@ -1,9 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "jsonpath_lib"
|
name = "jsonpath_lib"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
authors = ["Changseok Han <freestrings@gmail.com>"]
|
authors = ["Changseok Han <freestrings@gmail.com>"]
|
||||||
|
|
||||||
description = "JSONPath for Rust and Webassembly - Webassembly Demo: https://freestrings.github.io/jsonpath"
|
description = "JsonPath for Rust and Webassembly - Webassembly Demo: https://freestrings.github.io/jsonpath"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
|
||||||
keywords = ["library", "jsonpath", "json", "webassembly"]
|
keywords = ["library", "jsonpath", "json", "webassembly"]
|
||||||
@ -11,7 +11,9 @@ keywords = ["library", "jsonpath", "json", "webassembly"]
|
|||||||
repository = "https://github.com/freestrings/jsonpath"
|
repository = "https://github.com/freestrings/jsonpath"
|
||||||
documentation = "https://docs.rs/jsonpath_lib/0.1.0/jsonpath_lib"
|
documentation = "https://docs.rs/jsonpath_lib/0.1.0/jsonpath_lib"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
license-file = "LICENSE"
|
|
||||||
|
[badges]
|
||||||
|
travis-ci = { repository = "freestrings/jsonpath", branch = "master" }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
164
README.md
164
README.md
@ -1,15 +1,40 @@
|
|||||||
# Jsonpath Library
|
# jsonpath-lib
|
||||||
|
|
||||||
[JsonPath](https://goessner.net/articles/JsonPath/) Rust 구현
|
[](https://travis-ci.org/freestrings/jsonpath)
|
||||||
|
|
||||||
|
`Rust` 버전 [JsonPath](https://goessner.net/articles/JsonPath/) 구현이다. Rust 구현과 동일한 기능을 `Webassembly` 로 제공하는 것 또한 목적이다.
|
||||||
|
|
||||||
|
The `Rust` version is a [JsonPath](https://goessner.net/articles/JsonPath/) implementation. It is also aimed to provide the same functionality as `Webassembly` in Rust implementation.
|
||||||
|
|
||||||
## 왜?
|
## 왜?
|
||||||
To enjoy Rust
|
|
||||||
|
|
||||||
## 사용법
|
To enjoy Rust!
|
||||||
|
|
||||||
|
## 목차
|
||||||
|
|
||||||
|
[With Javascript (Webassembly)](#with-javascript-webassembly)
|
||||||
|
|
||||||
|
- [jsonpath-wasm library](#jsonpath-wasm-library)
|
||||||
|
- [javascript - jsonpath.read(json: string|object, jsonpath: string)](#javascript---jsonpathreadjson-stringobject-jsonpath-string)
|
||||||
|
- [javascript - jsonpath.compile(jsonpath: string)](#javascript---jsonpathcompilejsonpath-string)
|
||||||
|
- [javascript - jsonpath.reader(json: string|object)](#javascript---jsonpathreaderjson-stringobject)
|
||||||
|
- [javascript - examples](#javascript---examples)
|
||||||
|
|
||||||
|
[With Rust (as library)](#with-rust-as-library)
|
||||||
|
|
||||||
|
- [jsonpath_lib library](#jsonpath_lib-library)
|
||||||
|
- [rust - jsonpath::read(json: serde_json::value::Value, jsonpath: &str)](#rust---jsonpathreadjson-serde_jsonvaluevalue-jsonpath-str)
|
||||||
|
- [rust - jsonpath::compile(jsonpath: &str)](#rust---jsonpathcompilejsonpath-str)
|
||||||
|
- [rust - jsonpath::reader(json: serde_json::value::Value)](#rust---jsonpathreaderjson-serde_jsonvaluevalue)
|
||||||
|
- [rust - examples](#rust---examples)
|
||||||
|
|
||||||
|
[With AWS API Gateway](#with-aws-api-gateway)
|
||||||
|
|
||||||
|
[Benchmark](#benchmark)
|
||||||
|
|
||||||
## With Javascript (WebAssembly)
|
## With Javascript (WebAssembly)
|
||||||
|
|
||||||
#### `jsonpath-wasm` 라이브리러
|
### jsonpath-wasm library
|
||||||
|
|
||||||
*(not yet published `jsonpath-wasm`)*
|
*(not yet published `jsonpath-wasm`)*
|
||||||
```javascript
|
```javascript
|
||||||
@ -19,7 +44,7 @@ import * as jsonpath from "jsonpath-wasm";
|
|||||||
let jsonpath = require('jsonpath-wasm');
|
let jsonpath = require('jsonpath-wasm');
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `read` 함수
|
### javascript - jsonpath.read(json: string|object, jsonpath: string)
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
let jsonObj = {
|
let jsonObj = {
|
||||||
@ -38,7 +63,7 @@ console.log(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
#### JsonPath 재사용
|
### javascript - jsonpath.compile(jsonpath: string)
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
let template = jsonpath.compile("$..friends[0]");
|
let template = jsonpath.compile("$..friends[0]");
|
||||||
@ -50,29 +75,32 @@ let jsonObj = {
|
|||||||
"friends": [ {"id": 0}, {"id": 1} ]
|
"friends": [ {"id": 0}, {"id": 1} ]
|
||||||
};
|
};
|
||||||
|
|
||||||
let ret = [ {"id": 0}, {"id": 0} ];
|
let ret = JSON.stringify([ {"id": 0}, {"id": 0} ]);
|
||||||
|
|
||||||
// 1. read as json object
|
// 1. read as json object
|
||||||
console.log(JSON.stringify(template(jsonObj)) == JSON.stringify(ret));
|
console.log(JSON.stringify(template(jsonObj)) == ret);
|
||||||
// 2. read as json string
|
// 2. read as json string
|
||||||
console.log(JSON.stringify(template(JSON.stringify(jsonObj))) == JSON.stringify(ret));
|
console.log(JSON.stringify(template(JSON.stringify(jsonObj))) == ret);
|
||||||
|
|
||||||
let jsonObj2 = {
|
let jsonObj2 = {
|
||||||
"school": {
|
"school": {
|
||||||
"friends": [ {"name": "Millicent Norman"}, {"name": "Vincent Cannon"} ]
|
"friends": [
|
||||||
|
{"name": "Millicent Norman"},
|
||||||
|
{"name": "Vincent Cannon"}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"friends": [ {"id": 0}, {"id": 1} ]
|
"friends": [ {"id": 0}, {"id": 1} ]
|
||||||
};
|
};
|
||||||
|
|
||||||
let ret2 = [ {"id": 0}, {"name": "Millicent Norman"} ];
|
let ret2 = JSON.stringify([ {"id": 0}, {"name": "Millicent Norman"} ]);
|
||||||
|
|
||||||
// 1. read as json object
|
// 1. read as json object
|
||||||
console.log(JSON.stringify(template(jsonObj2)) == JSON.stringify(ret2));
|
console.log(JSON.stringify(template(jsonObj2)) == ret2);
|
||||||
// 2. read as json string
|
// 2. read as json string
|
||||||
console.log(JSON.stringify(template(JSON.stringify(jsonObj2))) == JSON.stringify(ret2));
|
console.log(JSON.stringify(template(JSON.stringify(jsonObj2))) == ret2);
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Json 재사용
|
### javascript - jsonpath.reader(json: string|object)
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
let jsonObj = {
|
let jsonObj = {
|
||||||
@ -82,18 +110,21 @@ let jsonObj = {
|
|||||||
"friends": [{"id": 0},{"id": 1}]
|
"friends": [{"id": 0},{"id": 1}]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let ret1 = JSON.stringify([ {"id": 0}, {"id": 0} ]);
|
||||||
|
let ret2 = JSON.stringify([ {"id": 1}, {"id": 1} ]);
|
||||||
|
|
||||||
// 1. read as json object
|
// 1. read as json object
|
||||||
let reader = jsonpath.reader(jsonObj);
|
let reader = jsonpath.reader(jsonObj);
|
||||||
console.log(JSON.stringify(reader("$..friends[0]")) == JSON.stringify([ {"id": 0}, {"id": 0} ]));
|
console.log(JSON.stringify(reader("$..friends[0]")) == ret1);
|
||||||
console.log(JSON.stringify(reader("$..friends[1]")) == JSON.stringify([ {"id": 1}, {"id": 1} ]));
|
console.log(JSON.stringify(reader("$..friends[1]")) == ret2);
|
||||||
|
|
||||||
// 2. read as json string
|
// 2. read as json string
|
||||||
let reader2 = jsonpath.reader(JSON.stringify(jsonObj));
|
let reader2 = jsonpath.reader(JSON.stringify(jsonObj));
|
||||||
console.log(JSON.stringify(reader2("$..friends[0]")) == JSON.stringify([ {"id": 0}, {"id": 0} ]));
|
console.log(JSON.stringify(reader2("$..friends[0]")) == ret1);
|
||||||
console.log(JSON.stringify(reader2("$..friends[1]")) == JSON.stringify([ {"id": 1}, {"id": 1} ]));
|
console.log(JSON.stringify(reader2("$..friends[1]")) == ret2);
|
||||||
```
|
```
|
||||||
|
|
||||||
### 예제
|
### javascript - examples
|
||||||
|
|
||||||
**Demo**: https://freestrings.github.io/jsonpath/
|
**Demo**: https://freestrings.github.io/jsonpath/
|
||||||
|
|
||||||
@ -156,18 +187,20 @@ json 데이터 *(참고 사이트: https://github.com/json-path/JsonPath)*
|
|||||||
| <a href="https://freestrings.github.io/jsonpath/?path=$..book[?(@.isbn)]" target="_blank">$..book[?(@.isbn)]</a> | All books with an ISBN number |
|
| <a href="https://freestrings.github.io/jsonpath/?path=$..book[?(@.isbn)]" target="_blank">$..book[?(@.isbn)]</a> | All books with an ISBN number |
|
||||||
| <a href="https://freestrings.github.io/jsonpath/?path=$.store.book[?(@.price < 10)]" target="_blank">$.store.book[?(@.price < 10)]</a> | All books in store cheaper than 10 |
|
| <a href="https://freestrings.github.io/jsonpath/?path=$.store.book[?(@.price < 10)]" target="_blank">$.store.book[?(@.price < 10)]</a> | All books in store cheaper than 10 |
|
||||||
| <a href="https://freestrings.github.io/jsonpath/?path=$..*" target="_blank">$..*</a> | Give me every thing
|
| <a href="https://freestrings.github.io/jsonpath/?path=$..*" target="_blank">$..*</a> | Give me every thing
|
||||||
| <a href="https://freestrings.github.io/jsonpath/?path=%24..book%5B%3F((%40.price%20%3D%3D%2012.99%20%7C%7C%20%24.store.bicycle.price%20%3C%20%40.price)%20%7C%7C%20%40.category%20%3D%3D%20%22reference%22)%5D" target="_blank">$..book[?((@.price == 12.99 | | $.store.bicycle.price < @.price) || @.category == "reference")]</a> | Complex filter
|
| <a href="https://freestrings.github.io/jsonpath/?path=%24..book%5B%3F((%40.price%20%3D%3D%2012.99%20%7C%7C%20%24.store.bicycle.price%20%3C%20%40.price)%20%7C%7C%20%40.category%20%3D%3D%20%22reference%22)%5D" target="_blank">$..book[ ?(<br>(@.price == 12.99 | | $.store.bicycle.price < @.price)<br> || @.category == "reference"<br>)]</a> | Complex filter
|
||||||
|
|
||||||
|
|
||||||
## With Rust (as library)
|
## With Rust (as library)
|
||||||
|
|
||||||
|
### jsonpath_lib library
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
extern crate jsonpath_lib as jsonpath;
|
extern crate jsonpath_lib as jsonpath;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `read` 함수
|
### rust - jsonpath::read(json: serde_json::value::Value, jsonpath: &str)
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
let json_obj = json!({
|
let json_obj = json!({
|
||||||
@ -181,7 +214,7 @@ let ret = json!([ {"id": 0}, {"id": 0} ]);
|
|||||||
assert_eq!(json, ret)
|
assert_eq!(json, ret)
|
||||||
```
|
```
|
||||||
|
|
||||||
#### JsonPath 재사용
|
### rust - jsonpath::compile(jsonpath: &str)
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
let mut template = jsonpath::compile("$..friends[0]");
|
let mut template = jsonpath::compile("$..friends[0]");
|
||||||
@ -209,7 +242,7 @@ let ret = json!([ {"id": 0}, {"name": "Millicent Norman"} ]);
|
|||||||
assert_eq!(json, ret);
|
assert_eq!(json, ret);
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Json 재사용
|
### rust - jsonpath::reader(json: serde_json::value::Value)
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
let json_obj = json!({
|
let json_obj = json!({
|
||||||
@ -230,7 +263,7 @@ let ret = json!([ {"id": 1}, {"id": 1} ]);
|
|||||||
assert_eq!(json, ret);
|
assert_eq!(json, ret);
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 예제
|
### rust - examples
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
let json_obj = json!({
|
let json_obj = json!({
|
||||||
@ -273,9 +306,10 @@ let json_obj = json!({
|
|||||||
|
|
||||||
let mut reader = jsonpath::reader(json_obj);
|
let mut reader = jsonpath::reader(json_obj);
|
||||||
|
|
||||||
//
|
```
|
||||||
// $.store.book[*].author
|
|
||||||
//
|
#### $.store.book[*].author
|
||||||
|
```rust
|
||||||
let json = reader("$.store.book[*].author").unwrap();
|
let json = reader("$.store.book[*].author").unwrap();
|
||||||
let ret = json!([
|
let ret = json!([
|
||||||
"Nigel Rees",
|
"Nigel Rees",
|
||||||
@ -284,10 +318,10 @@ let ret = json!([
|
|||||||
"J. R. R. Tolkien"
|
"J. R. R. Tolkien"
|
||||||
]);
|
]);
|
||||||
assert_eq!(json, ret);
|
assert_eq!(json, ret);
|
||||||
|
```
|
||||||
|
|
||||||
//
|
#### $..author
|
||||||
// $..author
|
```rust
|
||||||
//
|
|
||||||
let json = reader("$..author").unwrap();
|
let json = reader("$..author").unwrap();
|
||||||
let ret = json!([
|
let ret = json!([
|
||||||
"Nigel Rees",
|
"Nigel Rees",
|
||||||
@ -296,10 +330,10 @@ let ret = json!([
|
|||||||
"J. R. R. Tolkien"
|
"J. R. R. Tolkien"
|
||||||
]);
|
]);
|
||||||
assert_eq!(json, ret);
|
assert_eq!(json, ret);
|
||||||
|
```
|
||||||
|
|
||||||
//
|
#### $.store.*
|
||||||
// $.store.*
|
```rust
|
||||||
//
|
|
||||||
let json = reader("$.store.*").unwrap();
|
let json = reader("$.store.*").unwrap();
|
||||||
let ret = json!([
|
let ret = json!([
|
||||||
[
|
[
|
||||||
@ -336,17 +370,17 @@ let ret = json!([
|
|||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
assert_eq!(ret, json);
|
assert_eq!(ret, json);
|
||||||
|
```
|
||||||
|
|
||||||
//
|
#### $.store..price
|
||||||
// $.store..price
|
```rust
|
||||||
//
|
|
||||||
let json = reader("$.store..price").unwrap();
|
let json = reader("$.store..price").unwrap();
|
||||||
let ret = json!([8.95, 12.99, 8.99, 22.99, 19.95]);
|
let ret = json!([8.95, 12.99, 8.99, 22.99, 19.95]);
|
||||||
assert_eq!(ret, json);
|
assert_eq!(ret, json);
|
||||||
|
```
|
||||||
|
|
||||||
//
|
#### $..book[2]
|
||||||
// $..book[2]
|
```rust
|
||||||
//
|
|
||||||
let json = reader("$..book[2]").unwrap();
|
let json = reader("$..book[2]").unwrap();
|
||||||
let ret = json!([{
|
let ret = json!([{
|
||||||
"category" : "fiction",
|
"category" : "fiction",
|
||||||
@ -356,10 +390,10 @@ let ret = json!([{
|
|||||||
"price" : 8.99
|
"price" : 8.99
|
||||||
}]);
|
}]);
|
||||||
assert_eq!(ret, json);
|
assert_eq!(ret, json);
|
||||||
|
```
|
||||||
|
|
||||||
//
|
#### $..book[-2]
|
||||||
// $..book[-2]
|
```rust
|
||||||
//
|
|
||||||
let json = reader("$..book[-2]").unwrap();
|
let json = reader("$..book[-2]").unwrap();
|
||||||
let ret = json!([{
|
let ret = json!([{
|
||||||
"category" : "fiction",
|
"category" : "fiction",
|
||||||
@ -369,10 +403,10 @@ let ret = json!([{
|
|||||||
"price" : 8.99
|
"price" : 8.99
|
||||||
}]);
|
}]);
|
||||||
assert_eq!(ret, json);
|
assert_eq!(ret, json);
|
||||||
|
```
|
||||||
|
|
||||||
//
|
#### $..book[0,1]
|
||||||
// $..book[0,1]
|
```rust
|
||||||
//
|
|
||||||
let json = reader("$..book[0,1]").unwrap();
|
let json = reader("$..book[0,1]").unwrap();
|
||||||
let ret = json!([
|
let ret = json!([
|
||||||
{
|
{
|
||||||
@ -389,10 +423,10 @@ let ret = json!([
|
|||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
assert_eq!(ret, json);
|
assert_eq!(ret, json);
|
||||||
|
```
|
||||||
|
|
||||||
//
|
#### $..book[:2]
|
||||||
// $..book[:2]
|
```rust
|
||||||
//
|
|
||||||
let json = reader("$..book[:2]").unwrap();
|
let json = reader("$..book[:2]").unwrap();
|
||||||
let ret = json!([
|
let ret = json!([
|
||||||
{
|
{
|
||||||
@ -409,10 +443,10 @@ let ret = json!([
|
|||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
assert_eq!(ret, json);
|
assert_eq!(ret, json);
|
||||||
|
```
|
||||||
|
|
||||||
//
|
#### $..book[2:]
|
||||||
// $..book[2:]
|
```rust
|
||||||
//
|
|
||||||
let json = reader("$..book[2:]").unwrap();
|
let json = reader("$..book[2:]").unwrap();
|
||||||
let ret = json!([
|
let ret = json!([
|
||||||
{
|
{
|
||||||
@ -431,10 +465,10 @@ let ret = json!([
|
|||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
assert_eq!(ret, json);
|
assert_eq!(ret, json);
|
||||||
|
```
|
||||||
|
|
||||||
//
|
#### $..book[?(@.isbn)]
|
||||||
// $..book[?(@.isbn)]
|
```rust
|
||||||
//
|
|
||||||
let json = reader("$..book[?(@.isbn)]").unwrap();
|
let json = reader("$..book[?(@.isbn)]").unwrap();
|
||||||
let ret = json!([
|
let ret = json!([
|
||||||
{
|
{
|
||||||
@ -453,10 +487,10 @@ let ret = json!([
|
|||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
assert_eq!(ret, json);
|
assert_eq!(ret, json);
|
||||||
|
```
|
||||||
|
|
||||||
//
|
#### $.store.book[?(@.price < 10)]
|
||||||
// $.store.book[?(@.price < 10)]
|
```rust
|
||||||
//
|
|
||||||
let json = reader("$.store.book[?(@.price < 10)]").unwrap();
|
let json = reader("$.store.book[?(@.price < 10)]").unwrap();
|
||||||
let ret = json!([
|
let ret = json!([
|
||||||
{
|
{
|
||||||
@ -474,11 +508,15 @@ let ret = json!([
|
|||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
assert_eq!(ret, json);
|
assert_eq!(ret, json);
|
||||||
|
```
|
||||||
|
|
||||||
//
|
#### $..book[?((@.price == 12.99 || $.store.bicycle.price < @.price) || @.category == "reference")]
|
||||||
// $..book[?((@.price == 12.99 || $.store.bicycle.price < @.price) || @.category == "reference")]
|
```rust
|
||||||
//
|
let json = reader(r#"$..book[
|
||||||
let json = reader("$..book[?((@.price == 12.99 || $.store.bicycle.price < @.price) || @.category == "reference")]").unwrap();
|
?(
|
||||||
|
(@.price == 12.99 || $.store.bicycle.price < @.price)
|
||||||
|
|| @.category == "reference"
|
||||||
|
)]"#).unwrap();
|
||||||
let ret = json!([
|
let ret = json!([
|
||||||
{
|
{
|
||||||
"category": "fiction",
|
"category": "fiction",
|
||||||
@ -507,5 +545,5 @@ assert_eq!(ret, json);
|
|||||||
|
|
||||||
-
|
-
|
||||||
|
|
||||||
# 성능테스트
|
## Benchmark
|
||||||
|
|
||||||
|
20
src/lib.rs
20
src/lib.rs
@ -1,10 +1,9 @@
|
|||||||
//! JSONPath implementation for Rust
|
//! JsonPath implementation for Rust
|
||||||
//!
|
//!
|
||||||
//! # Example
|
//! # Example
|
||||||
//! ```
|
//! ```
|
||||||
//! extern crate jsonpath_lib as jsonpath;
|
//! extern crate jsonpath_lib as jsonpath;
|
||||||
//! #[macro_use]
|
//! #[macro_use] extern crate serde_json;
|
||||||
//! extern crate serde_json;
|
|
||||||
//!
|
//!
|
||||||
//! let json_obj = json!({
|
//! let json_obj = json!({
|
||||||
//! "store": {
|
//! "store": {
|
||||||
@ -158,14 +157,14 @@
|
|||||||
//! ]);
|
//! ]);
|
||||||
//! assert_eq!(ret, json);
|
//! assert_eq!(ret, json);
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
extern crate env_logger;
|
extern crate env_logger;
|
||||||
|
|
||||||
extern crate serde;
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[macro_use]
|
#[macro_use] extern crate serde_json;
|
||||||
extern crate serde_json;
|
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
@ -189,6 +188,9 @@ type Result = result::Result<Value, String>;
|
|||||||
/// # Read multiple Json multiple times with the same JsonPath
|
/// # Read multiple Json multiple times with the same JsonPath
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// extern crate jsonpath_lib as jsonpath;
|
||||||
|
/// #[macro_use] extern crate serde_json;
|
||||||
|
///
|
||||||
/// let mut template = jsonpath::compile("$..friends[0]");
|
/// let mut template = jsonpath::compile("$..friends[0]");
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
@ -234,6 +236,9 @@ pub fn compile<'a>(path: &'a str) -> impl FnMut(Value) -> Result + 'a {
|
|||||||
/// # Read the same Json multiple times using different JsonPath
|
/// # Read the same Json multiple times using different JsonPath
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// extern crate jsonpath_lib as jsonpath;
|
||||||
|
/// #[macro_use] extern crate serde_json;
|
||||||
|
///
|
||||||
/// let json_obj = json!({
|
/// let json_obj = json!({
|
||||||
/// "school": {
|
/// "school": {
|
||||||
/// "friends": [{"id": 0}, {"id": 1}]
|
/// "friends": [{"id": 0}, {"id": 1}]
|
||||||
@ -264,6 +269,9 @@ pub fn reader(json: Value) -> impl FnMut(&str) -> Result {
|
|||||||
/// # Read Json using JsonPath
|
/// # Read Json using JsonPath
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// extern crate jsonpath_lib as jsonpath;
|
||||||
|
/// #[macro_use] extern crate serde_json;
|
||||||
|
///
|
||||||
/// let json_obj = json!({
|
/// let json_obj = json!({
|
||||||
/// "school": {
|
/// "school": {
|
||||||
/// "friends": [{"id": 0}, {"id": 1}]
|
/// "friends": [{"id": 0}, {"id": 1}]
|
||||||
|
@ -1,69 +0,0 @@
|
|||||||
language: rust
|
|
||||||
sudo: false
|
|
||||||
|
|
||||||
cache: cargo
|
|
||||||
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
|
|
||||||
# Builds with wasm-pack.
|
|
||||||
- rust: beta
|
|
||||||
env: RUST_BACKTRACE=1
|
|
||||||
addons:
|
|
||||||
firefox: latest
|
|
||||||
chrome: stable
|
|
||||||
before_script:
|
|
||||||
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
|
|
||||||
- (test -x $HOME/.cargo/bin/cargo-generate || cargo install --vers "^0.2" cargo-generate)
|
|
||||||
- cargo install-update -a
|
|
||||||
- curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -f
|
|
||||||
script:
|
|
||||||
- cargo generate --git . --name testing
|
|
||||||
# Having a broken Cargo.toml (in that it has curlies in fields) anywhere
|
|
||||||
# in any of our parent dirs is problematic.
|
|
||||||
- mv Cargo.toml Cargo.toml.tmpl
|
|
||||||
- cd testing
|
|
||||||
- wasm-pack build
|
|
||||||
- wasm-pack test --chrome --firefox --headless
|
|
||||||
|
|
||||||
# Builds on nightly.
|
|
||||||
- rust: nightly
|
|
||||||
env: RUST_BACKTRACE=1
|
|
||||||
before_script:
|
|
||||||
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
|
|
||||||
- (test -x $HOME/.cargo/bin/cargo-generate || cargo install --vers "^0.2" cargo-generate)
|
|
||||||
- cargo install-update -a
|
|
||||||
- rustup target add wasm32-unknown-unknown
|
|
||||||
script:
|
|
||||||
- cargo generate --git . --name testing
|
|
||||||
- mv Cargo.toml Cargo.toml.tmpl
|
|
||||||
- cd testing
|
|
||||||
- cargo check
|
|
||||||
- cargo check --target wasm32-unknown-unknown
|
|
||||||
- cargo check --no-default-features
|
|
||||||
- cargo check --target wasm32-unknown-unknown --no-default-features
|
|
||||||
- cargo check --no-default-features --features console_error_panic_hook
|
|
||||||
- cargo check --target wasm32-unknown-unknown --no-default-features --features console_error_panic_hook
|
|
||||||
- cargo check --no-default-features --features "console_error_panic_hook wee_alloc"
|
|
||||||
- cargo check --target wasm32-unknown-unknown --no-default-features --features "console_error_panic_hook wee_alloc"
|
|
||||||
|
|
||||||
# Builds on beta.
|
|
||||||
- rust: beta
|
|
||||||
env: RUST_BACKTRACE=1
|
|
||||||
before_script:
|
|
||||||
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
|
|
||||||
- (test -x $HOME/.cargo/bin/cargo-generate || cargo install --vers "^0.2" cargo-generate)
|
|
||||||
- cargo install-update -a
|
|
||||||
- rustup target add wasm32-unknown-unknown
|
|
||||||
script:
|
|
||||||
- cargo generate --git . --name testing
|
|
||||||
- mv Cargo.toml Cargo.toml.tmpl
|
|
||||||
- cd testing
|
|
||||||
- cargo check
|
|
||||||
- cargo check --target wasm32-unknown-unknown
|
|
||||||
- cargo check --no-default-features
|
|
||||||
- cargo check --target wasm32-unknown-unknown --no-default-features
|
|
||||||
- cargo check --no-default-features --features console_error_panic_hook
|
|
||||||
- cargo check --target wasm32-unknown-unknown --no-default-features --features console_error_panic_hook
|
|
||||||
# Note: no enabling the `wee_alloc` feature here because it requires
|
|
||||||
# nightly for now.
|
|
@ -1,9 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "jsonpath-wasm"
|
name = "jsonpath-wasm"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
authors = ["Changseok Han <freestrings@gmail.com>"]
|
authors = ["Changseok Han <freestrings@gmail.com>"]
|
||||||
|
|
||||||
description = "JSONPath Webassembly compiled by Rust - Demo: https://freestrings.github.io/jsonpath"
|
description = "JsonPath Webassembly version compiled by Rust - Demo: https://freestrings.github.io/jsonpath"
|
||||||
|
|
||||||
keywords = ["library", "jsonpath", "json", "webassembly"]
|
keywords = ["library", "jsonpath", "json", "webassembly"]
|
||||||
|
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
language: node_js
|
|
||||||
node_js: "10"
|
|
||||||
|
|
||||||
script:
|
|
||||||
- ./node_modules/.bin/webpack
|
|
Loading…
x
Reference in New Issue
Block a user