Skip to content

Commit b503862

Browse files
committed
doc: README.md updated
1 parent f4b7a20 commit b503862

1 file changed

Lines changed: 49 additions & 3 deletions

File tree

README.md

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ pip install streamson
1212
```
1313

1414
## Usage
15-
### Simple
15+
### Select users
1616
```python
1717
>>> import streamson
18-
>>> data = [b'{"users": ["john","carl","bob"]}']
19-
>>> extracted = streamson.extract_iter((e for e in data), ['{"users"}[]'])
18+
>>> data = [b'{"users": ["john","carl","bob"], "groups": ["admins", "staff"], "org": "university"}']
19+
>>> matcher = streamson.SimpleMatcher('{"users"}[]'])
20+
>>> extracted = streamson.extract_iter((e for e in data), matcher)
2021
>>> for path, parsed in extracted:
2122
... path, parsed
2223
...
@@ -25,6 +26,51 @@ pip install streamson
2526
('{"users"}[2]', 'bob')
2627
```
2728

29+
### Select users and groups
30+
```python
31+
>>> import streamson
32+
>>> data = [b'{"users": ["john","carl","bob"], "groups": ["admins", "staff"], "org": "university"}']
33+
>>> matcher = streamson.SimpleMatcher('{"users"}[]']) | streamson.SimpleMatcher('{"groups"}[]'])
34+
>>> extracted = streamson.extract_iter((e for e in data), matcher)
35+
>>> for path, parsed in extracted:
36+
... path, parsed
37+
...
38+
('{"users"}[0]', 'john')
39+
('{"users"}[1]', 'carl')
40+
('{"users"}[2]', 'bob')
41+
('{"groups"}[0]', 'admins')
42+
('{"groups"}[1]', 'staff')
43+
```
44+
45+
### Select only first level parts
46+
```python
47+
>>> import streamson
48+
>>> data = [b'{"users": ["john","carl","bob"], "groups": ["admins", "staff"], "org": "university"}']
49+
>>> matcher = streamson.DepthMatcher(1, 1)
50+
>>> extracted = streamson.extract_iter((e for e in data), matcher)
51+
>>> for path, parsed in extracted:
52+
... path, parsed
53+
...
54+
('{"users"}', ['john', 'carl', 'bob'])
55+
('{"groups"}', ['admins', 'staff'])
56+
('{"org"}', 'university')
57+
```
58+
59+
### Select second first level parts exclude first records
60+
```python
61+
>>> import streamson
62+
>>> data = [b'{"users": ["john","carl","bob"], "groups": ["admins", "staff"], "org": "university"}']
63+
>>> matcher = streamson.DepthMatcher(2, 2) & ~streamson.SimpleMatcher('{}[0]')
64+
>>> extracted = streamson.extract_iter((e for e in data), matcher)
65+
>>> for path, parsed in extracted:
66+
... path, parsed
67+
...
68+
('{"users"}[1]', 'carl')
69+
('{"users"}[2]', 'bob')
70+
('{"groups"}[1]', 'staff')
71+
```
72+
73+
2874
## Motivation
2975
This project is meant to be use as a fast json splitter.
3076
Its main purpose is to split raw binary data instead of parsing it.

0 commit comments

Comments
 (0)