Streamson Lib
Rust library to handle large JSONs. It aims to be memory efficient as well as fast.
Note that it doesn't fully validates whether the input JSON is valid. This means that invalid JSONs might pass without an error.
Strategies
Strategy | Converts data | Buffers matched data | Nested matches | Uses handlers | Uses matchers |
---|---|---|---|---|---|
Trigger | No | No | Yes | Yes | Yes |
Filter | Yes | No | No | Yes | Yes |
Extract | Yes | No | No | Yes | Yes |
Convert | Yes | No | No | Yes | Yes |
All | Yes/No | No | No | Yes | No |
Trigger strategy
It triggers handlers on matched JSON parts. It doesn't return data as output.
Filter strategy
It actually alters the JSON. If the path is matched the matched part should be removed from output JSON. Handlers can be used here to e.g. store removed parts into a file.
Extract strategy
Alters the JSON as well. It returns only the matched parts as output. Handlers can be used to e.g. convert extracted parts.
Convert strategy
Alters the JSON by calling convert handlers to matched parts.
All strategy
Matches all data. Handlers can be used to convert the content of entire JSON or to perform some kind of analysis.
Matchers
Structures which are used to match a part of JSON.
Simple
It matches path in JSON. For example:
Simple path {"users"}[0]{"name"}
would match "carl"
.
Simple path {"users"}[]{"name"}
would match "carl"
and "bob"
.
Simple path {}[0]{"name"}
would match "carl"
and "admins"
.
Simple path ??{"name"}
would match "carl"
, "bob"
, "admins"
and "staff"
.
Simple path *{"name"}
would match "carl"
, "bob"
, "admins"
and "staff"
.
Depth
Matches depth in JSON path. It has min length and max length ranges (max is optional).
Regex
Matches path based on regex.
Example
use ;
use ;
let handler = new;
let matcher = from_str.unwrap;
let mut trigger = new;
trigger.add_matcher;
for input in vec!
Combinator
Wraps one or two matchers. It implements basic logic operators (NOT
, OR
and AND
).
Handlers
Analyser
Stores matched paths to analyze JSON structure.
Buffer
Buffers matched data which can be manually extracted later.
Output
Writes matched data into given output (e.g. file or stdout).
Indenter
Converts indentation of the matched data.
Indexer
Store indexes of the matched data.
Regex
Converts data based on regex.
Example
use ;
use ;
use regex;
let converter =
new;
let matcher = new.unwrap;
let mut convert = new;
// Set the matcher for convert strategy
convert.add_matcher;
for input in vec!
Replace
Replaces matched output by fixed data.
Shorten
Shortens matched data
Unstringify
Unstringifies matched data.
Examples
Trigger
use ;
use ;
use ;
let mut trigger = new;
let handler = new;
let matcher = new.unwrap;
trigger.add_matcher;
let mut buffer = ;
let mut input = "<input data>".as_bytes;
while let Ok = input.read
Filter
use ;
use *;
let mut filter = new;
let matcher = new.unwrap;
filter.add_matcher;
let mut buffer = ;
let mut input = "<input data>".as_bytes;
while let Ok = input.read
Extract
use ;
use *;
let mut extract = new;
let matcher = new.unwrap;
extract.add_matcher;
let mut buffer = ;
let mut input = "<input data>".as_bytes;
while let Ok = input.read
Convert
use ;
use ;
use *;
let mut convert = new;
let matcher = new.unwrap;
convert.add_matcher;
let mut buffer = ;
let mut input = "<input data>".as_bytes;
while let Ok = input.read
All
use ;
use ;
use *;
let mut all = new;
let analyser = new;
all.add_handler;
let mut buffer = ;
let mut input = "<input data>".as_bytes;
while let Ok = input.read
println!
Traits
Custom Handlers
You can define your custom handler.
use Any;
use ;
;
Custom Matchers
You can define custom matchers as well.
use ;
;