1
- <h1 align =" left " ><img src =" ./docs/gson -query.png " width =" 256 " alt =" gson -query" ></h1 >
1
+ <h1 align =" left " ><img src =" ./docs/json -query.png " width =" 256 " alt =" @sagold/json -query" ></h1 >
2
2
3
- ** ⚠️ package ` gson -query` has moved to ` @sagold/ json-query ` . Please change package source as ` gson-query ` will no longer be updated. **
3
+ > ` json -query` lets you quickly select values, patterns or types from json-data. Its input requires a simple string, describing a concise query into your data
4
4
5
- > gson-query lets you quickly select values, patterns or types from json-data. Its input requires a simple string, describing a concise query into your data
5
+ install
6
+
7
+ ` yarn add @sagold/json-query `
6
8
7
- ** npm package** ` gson-query ` . An es5-version is bundled at ` dist/gson-query.js ` . The command-line integration can be installed separately from [ gson-query-cli] ( https://github.com/sagold/gson-query-cli ) .
8
9
9
10
- [ Features] ( #features )
10
11
- [ Introduction] ( #quick-introduction )
31
32
Basically, a ** query** is a json-pointer, which describes a path of properties into the json-data
32
33
33
34
``` js
34
- import { get } from " gson -query" ;
35
+ import { get } from " @sagold/json -query" ;
35
36
const input = { object: { a: { id: " id-a" }, b: { id: " id-b" } } };
36
37
37
38
const values = get (input, " /object/a/id" ); // ["id-a"]
@@ -157,6 +158,7 @@ const values = get(input, "/(/a)+"); // [{ id: 2, a: { id: 3, a: 4 } }, { id: 3,
157
158
158
159
## Breaking Changes
159
160
161
+ - with version ` v5.0.0 ` package has been rename to ` @sagold/json-query `
160
162
- with version ` v4.0.0 ` (2019/10/01)
161
163
- the api has been simplified to methods ` query.get ` and ` query.delete ` (removed ` run ` and ` pattern ` )
162
164
- with version ` v3.0.0 `
@@ -167,7 +169,7 @@ const values = get(input, "/(/a)+"); // [{ id: 2, a: { id: 3, a: 4 } }, { id: 3,
167
169
168
170
## API
169
171
170
- * gson -query* exposes ` get ` , ` set ` , ` remove ` and a ` split ` -helper
172
+ * json -query* exposes ` get ` , ` set ` , ` remove ` and a ` split ` -helper
171
173
172
174
method | signature | description
173
175
--------|-------------------------------------------------------------------|------------------------------
@@ -182,7 +184,7 @@ remove | (input:any, query: string, returnRemoved?:boolean) | de
182
184
per default, * get* returns a list of all values
183
185
184
186
``` js
185
- import { get } from " gson -query" ;
187
+ import { get } from " @sagold/json -query" ;
186
188
const input = { object: { a: { id: 33 }, b: { id: " id-b" } } };
187
189
const values = get (input, " /**?:value" ); // [33, "id-b"]
188
190
```
@@ -201,7 +203,7 @@ function | callback with `(value, keyToValue, parentObject, jsonPointer) => {
201
203
202
204
203
205
``` js
204
- import { get } from " gson -query" ;
206
+ import { get } from " @sagold/json -query" ;
205
207
const input = { object: { a: { id: 33 }, b: { id: " id-b" } } };
206
208
207
209
get (input, " /**?:value" , get .VALUE ); // [33, "id-b"]
@@ -225,7 +227,7 @@ get(input, "/**?:value", (value, key, parent, pointer) => `custom-${pointer}`);
225
227
Note: the input will be modified. If this is unwanted behaviour, copy your data up front.
226
228
227
229
``` js
228
- import { remove } from " gson -query" ;
230
+ import { remove } from " @sagold/json -query" ;
229
231
const input = { object: { a: { id: 33 }, b: { id: " id-b" } } };
230
232
231
233
remove (input, " /object/*/id" ); // { object: { a: {}, b: {} } };
@@ -234,7 +236,7 @@ remove(input, "/object/*/id"); // { object: { a: {}, b: {} } };
234
236
Per default, the input object is returned. Setting the optional argument ` returnRemoved = true ` , will return a list of the removed items
235
237
236
238
``` js
237
- import { remove } from " gson -query" ;
239
+ import { remove } from " @sagold/json -query" ;
238
240
const input = { object: { a: { id: 33 }, b: { id: " id-b" } } };
239
241
240
242
remove (input, " /object/*/id" , true ); // [ 33, "id-b" ]
@@ -262,15 +264,15 @@ value(pointerOfParent:string, lastPropertyName:string, parentObject:string, poin
262
264
Create data from simple properties
263
265
264
266
```js
265
- import { set } from " gson -query" ;
267
+ import { set } from " @sagold/json -query" ;
266
268
267
269
const result = set ({}, " /object/id" , 42 ); // { object: { id: 42 }}
268
270
` ` `
269
271
270
272
Add properties to multiple existing objects
271
273
272
274
` ` ` js
273
- import { set } from " gson -query" ;
275
+ import { set } from " @sagold/json -query" ;
274
276
275
277
const result = set ({ list: [ { id: 1 }, { id: 2 } ] }, " /list/*/index" , 42 );
276
278
// { list: [ { id: 1, index: 42 }, { id: 2, index: 42 } ] }
@@ -279,7 +281,7 @@ const result = set({ list: [ { id: 1 }, { id: 2 } ] }, "/list/*/index", 42);
279
281
Or using a value-function
280
282
281
283
` ` ` js
282
- import { set } from " gson -query" ;
284
+ import { set } from " @sagold/json -query" ;
283
285
284
286
const result = set ({ list: [ { id: 1 }, { id: 2 } ] }, " /list/*/index" ,
285
287
( _ , _ , parent ) => ` id-${parent .id } `
@@ -290,15 +292,15 @@ const result = set({ list: [ { id: 1 }, { id: 2 } ] }, "/list/*/index",
290
292
Currently, ` set ` will not override simple values
291
293
292
294
` ` ` js
293
- import { set } from " gson -query" ;
295
+ import { set } from " @sagold/json -query" ;
294
296
295
297
const result = set ({ value: 2 }, " /value/id" , 3 );
296
298
// { value: 2 }
297
299
` ` `
298
300
299
301
And queries will not add values to the data
300
302
` ` ` js
301
- import { set } from " gson -query" ;
303
+ import { set } from " @sagold/json -query" ;
302
304
303
305
const result = set ({ a: { id: 2 } }, " ((/a), (/b))/id" , true );
304
306
// { a: { id: true } }
0 commit comments