mirror of
https://github.com/fluencelabs/jsonpath
synced 2025-05-04 13:42:13 +00:00
README.md - update
This commit is contained in:
parent
c122fe18d3
commit
ca5d9bda4a
145
README.md
145
README.md
@ -9,45 +9,122 @@ To enjoy Rust
|
||||
|
||||
## With Javascript (WebAssembly)
|
||||
|
||||
#### `jsonpath-wasm` 라이브리러
|
||||
|
||||
[Demo]: https://freestrings.github.io/jsonpath/
|
||||
|
||||
**(not yet published `jsonpath-wasm`)**
|
||||
|
||||
*(not yet published `jsonpath-wasm`)**
|
||||
```javascript
|
||||
import * as jsonpath from "jsonpath-wasm";
|
||||
|
||||
//
|
||||
// data
|
||||
//
|
||||
let jsonString = "{\"a\" : 1}";
|
||||
|
||||
//
|
||||
// reuse a compiled jsonpath
|
||||
//
|
||||
let template = jsonpath.compile("$.a");
|
||||
// read as json string
|
||||
template(jsonString)
|
||||
// read as json object
|
||||
template(JSON.parse(jsonString));
|
||||
|
||||
//
|
||||
// reuse a json
|
||||
//
|
||||
|
||||
// as json string
|
||||
let reader1 = jsonpath.reader(jsonString);
|
||||
reader1("$.a");
|
||||
|
||||
// as json object
|
||||
let reader2 = jsonpath.reader(JSON.parse(jsonString));
|
||||
reader2("$.a");
|
||||
|
||||
// read every time
|
||||
jsonpath.read(JSON.parse(jsonString), "$.a");
|
||||
jsonpath.read(jsonString, "$.a");
|
||||
```
|
||||
|
||||
#### `read` 함수
|
||||
|
||||
```
|
||||
jsonpath.read(JSON.parse("{\"a\" : 1}"), "$.a");
|
||||
jsonpath.read("{\"a\" : 1}", "$.a");
|
||||
```
|
||||
|
||||
|
||||
#### JsonPath 재사용
|
||||
|
||||
```
|
||||
let template = jsonpath.compile("$.a");
|
||||
|
||||
//
|
||||
// 1. read json string
|
||||
//
|
||||
template("{\"a\" : 1}")
|
||||
|
||||
//
|
||||
// 2. read as json object
|
||||
//
|
||||
template(JSON.parse("{\"a\" : 1}"));
|
||||
```
|
||||
|
||||
#### Json 재사용
|
||||
|
||||
```
|
||||
//
|
||||
// 1. read json string
|
||||
//
|
||||
let reader1 = jsonpath.reader("{\"a\" : 1}");
|
||||
reader1("$.a");
|
||||
reader1("$.b");
|
||||
|
||||
//
|
||||
// 2. read as json object
|
||||
//
|
||||
let reader2 = jsonpath.reader(JSON.parse("{\"a\" : 1}"));
|
||||
reader2("$.a");
|
||||
reader2("$.b");
|
||||
```
|
||||
|
||||
### 데모
|
||||
|
||||
**Demo**: https://freestrings.github.io/jsonpath/
|
||||
|
||||
json 데이터 *(참고 사이트: https://github.com/json-path/JsonPath)*
|
||||
|
||||
```javascript
|
||||
{
|
||||
"store": {
|
||||
"book": [
|
||||
{
|
||||
"category": "reference",
|
||||
"author": "Nigel Rees",
|
||||
"title": "Sayings of the Century",
|
||||
"price": 8.95
|
||||
},
|
||||
{
|
||||
"category": "fiction",
|
||||
"author": "Evelyn Waugh",
|
||||
"title": "Sword of Honour",
|
||||
"price": 12.99
|
||||
},
|
||||
{
|
||||
"category": "fiction",
|
||||
"author": "Herman Melville",
|
||||
"title": "Moby Dick",
|
||||
"isbn": "0-553-21311-3",
|
||||
"price": 8.99
|
||||
},
|
||||
{
|
||||
"category": "fiction",
|
||||
"author": "J. R. R. Tolkien",
|
||||
"title": "The Lord of the Rings",
|
||||
"isbn": "0-395-19395-8",
|
||||
"price": 22.99
|
||||
}
|
||||
],
|
||||
"bicycle": {
|
||||
"color": "red",
|
||||
"price": 19.95
|
||||
}
|
||||
},
|
||||
"expensive": 10
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
| JsonPath (click link to try)| Result |
|
||||
| :------- | :----- |
|
||||
| <a href="https://freestrings.github.io/jsonpath/?path=$.store.book[*].author" target="_blank">$.store.book[*].author</a>| The authors of all books |
|
||||
| <a href="https://freestrings.github.io/jsonpath/?path=$..author" target="_blank">$..author</a> | All authors |
|
||||
| <a href="https://freestrings.github.io/jsonpath/?path=$.store.*" target="_blank">$.store.*</a> | All things, both books and bicycles |
|
||||
| <a href="https://freestrings.github.io/jsonpath/?path=$.store..price" target="_blank">$.store..price</a> | The price of everything |
|
||||
| <a href="https://freestrings.github.io/jsonpath/?path=$..book[2]" target="_blank">$..book[2]</a> | The third book |
|
||||
| <a href="https://freestrings.github.io/jsonpath/?path=$..book[2]" target="_blank">$..book[-2]</a> | The second to last book |
|
||||
| <a href="https://freestrings.github.io/jsonpath/?path=$..book[0,1]" target="_blank">$..book[0,1]</a> | The first two books |
|
||||
| <a href="https://freestrings.github.io/jsonpath/?path=$..book[:2]" target="_blank">$..book[:2]</a> | All books from index 0 (inclusive) until index 2 (exclusive) |
|
||||
| <a href="https://freestrings.github.io/jsonpath/?path=$..book[1:2]" target="_blank">$..book[1:2]</a> | All books from index 1 (inclusive) until index 2 (exclusive) |
|
||||
| <a href="https://freestrings.github.io/jsonpath/?path=$..book[-2:]" target="_blank">$..book[-2:]</a> | Last two books |
|
||||
| <a href="https://freestrings.github.io/jsonpath/?path=$..book[2:]" target="_blank">$..book[2:]</a> | Book number two from tail |
|
||||
| <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 |
|
||||
| $..book[?(@.price <= $['expensive'])] *(not yet supported)* | ~~All books in store that are not "expensive"~~ |
|
||||
| $..book[?(@.author =~ /.*REES/i)] *(not yet supported)* | ~~All books matching regex (ignore case)~~ |
|
||||
| <a href="https://freestrings.github.io/jsonpath/?path=$..*" target="_blank">$..*</a> | Give me every thing
|
||||
| $..book.length() *(not yet supported)* | ~~The number of books~~ |
|
||||
|
||||
|
||||
## On Shell
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
BIN
docs/56e6d89b11a557631501.module.wasm
Normal file
BIN
docs/56e6d89b11a557631501.module.wasm
Normal file
Binary file not shown.
Binary file not shown.
14
docs/bootstrap.js
vendored
14
docs/bootstrap.js
vendored
@ -67,6 +67,9 @@
|
||||
/******/ "__wbindgen_string_new": function(p0i32,p1i32) {
|
||||
/******/ return installedModules["../pkg/jsonpath_wasm.js"].exports["__wbindgen_string_new"](p0i32,p1i32);
|
||||
/******/ },
|
||||
/******/ "__wbindgen_object_clone_ref": function(p0i32) {
|
||||
/******/ return installedModules["../pkg/jsonpath_wasm.js"].exports["__wbindgen_object_clone_ref"](p0i32);
|
||||
/******/ },
|
||||
/******/ "__wbindgen_cb_forget": function(p0i32) {
|
||||
/******/ return installedModules["../pkg/jsonpath_wasm.js"].exports["__wbindgen_cb_forget"](p0i32);
|
||||
/******/ },
|
||||
@ -76,17 +79,14 @@
|
||||
/******/ "__wbindgen_string_get": function(p0i32,p1i32) {
|
||||
/******/ return installedModules["../pkg/jsonpath_wasm.js"].exports["__wbindgen_string_get"](p0i32,p1i32);
|
||||
/******/ },
|
||||
/******/ "__wbindgen_object_clone_ref": function(p0i32) {
|
||||
/******/ return installedModules["../pkg/jsonpath_wasm.js"].exports["__wbindgen_object_clone_ref"](p0i32);
|
||||
/******/ },
|
||||
/******/ "__wbindgen_throw": function(p0i32,p1i32) {
|
||||
/******/ return installedModules["../pkg/jsonpath_wasm.js"].exports["__wbindgen_throw"](p0i32,p1i32);
|
||||
/******/ },
|
||||
/******/ "__wbindgen_closure_wrapper59": function(p0i32,p1i32,p2i32) {
|
||||
/******/ return installedModules["../pkg/jsonpath_wasm.js"].exports["__wbindgen_closure_wrapper59"](p0i32,p1i32,p2i32);
|
||||
/******/ },
|
||||
/******/ "__wbindgen_closure_wrapper61": function(p0i32,p1i32,p2i32) {
|
||||
/******/ return installedModules["../pkg/jsonpath_wasm.js"].exports["__wbindgen_closure_wrapper61"](p0i32,p1i32,p2i32);
|
||||
/******/ },
|
||||
/******/ "__wbindgen_closure_wrapper63": function(p0i32,p1i32,p2i32) {
|
||||
/******/ return installedModules["../pkg/jsonpath_wasm.js"].exports["__wbindgen_closure_wrapper63"](p0i32,p1i32,p2i32);
|
||||
/******/ }
|
||||
/******/ }
|
||||
/******/ };
|
||||
@ -186,7 +186,7 @@
|
||||
/******/ promises.push(installedWasmModuleData);
|
||||
/******/ else {
|
||||
/******/ var importObject = wasmImportObjects[wasmModuleId]();
|
||||
/******/ var req = fetch(__webpack_require__.p + "" + {"../pkg/jsonpath_wasm_bg.wasm":"71d16e2ce98524a4b795"}[wasmModuleId] + ".module.wasm");
|
||||
/******/ var req = fetch(__webpack_require__.p + "" + {"../pkg/jsonpath_wasm_bg.wasm":"56e6d89b11a557631501"}[wasmModuleId] + ".module.wasm");
|
||||
/******/ var promise;
|
||||
/******/ if(importObject instanceof Promise && typeof WebAssembly.compileStreaming === 'function') {
|
||||
/******/ promise = Promise.all([WebAssembly.compileStreaming(req), importObject]).then(function(items) {
|
||||
|
@ -7,7 +7,7 @@
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="container">
|
||||
<h3 style="margin-top: 15px;">JsonPath evaluator - Webassembly via Rust</h3>
|
||||
<h3 style="margin-top: 15px;">JsonPath evaluator with Webassembly via Rust</h3>
|
||||
<!--
|
||||
<div style="margin-top: -12px; margin-bottom: 10px;">
|
||||
<span id="version" style="font-size: xx-small"></span> -
|
||||
@ -22,9 +22,9 @@
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="input-group mb-3">
|
||||
<input type="text" id="jsonpath-input" class="form-control" placeholder="Enter path">
|
||||
<input type="text" id="jsonpath-input" class="form-control" placeholder="Enter 입력">
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text" id="read-json">Go!</span>
|
||||
<span class="input-group-text" id="read-json">실행</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -7,7 +7,7 @@
|
||||
</head>
|
||||
<body role="document">
|
||||
<div class="container">
|
||||
<h3 style="margin-top: 15px;">JsonPath evaluator - Webassembly via Rust</h3>
|
||||
<h3 style="margin-top: 15px;">JsonPath evaluator with Webassembly via Rust</h3>
|
||||
<!--
|
||||
<div style="margin-top: -12px; margin-bottom: 10px;">
|
||||
<span id="version" style="font-size: xx-small"></span> -
|
||||
@ -22,9 +22,9 @@
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="input-group mb-3">
|
||||
<input type="text" id="jsonpath-input" class="form-control" placeholder="Enter path">
|
||||
<input type="text" id="jsonpath-input" class="form-control" placeholder="Enter 입력">
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text" id="read-json">Go!</span>
|
||||
<span class="input-group-text" id="read-json">실행</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -45,4 +45,23 @@ function initEvent() {
|
||||
}
|
||||
}
|
||||
|
||||
initData('data/example.json').then(initEvent)
|
||||
function readPathParam() {
|
||||
let params = location.search.substr(1)
|
||||
.split('&')
|
||||
.map((item) => item.split('='))
|
||||
.reduce((acc, param) => {
|
||||
acc[param[0]] = decodeURIComponent(param[1]);
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
if(params.path) {
|
||||
getJsonpathInput().value = params.path;
|
||||
let doc = getReadBtn().ownerDocument;
|
||||
let event = doc.createEvent('MouseEvents');
|
||||
event.initEvent('click', true, true);
|
||||
event.synthetic = true;
|
||||
getReadBtn().dispatchEvent(event, true);
|
||||
}
|
||||
}
|
||||
|
||||
initData('data/example.json').then(initEvent).then(readPathParam);
|
Loading…
x
Reference in New Issue
Block a user