11 releases

0.4.0 Oct 11, 2021
0.3.2 Jan 2, 2021
0.3.1 Dec 28, 2020
0.2.0 Dec 22, 2020
0.1.1 Aug 12, 2020

#2162 in Parser implementations

Download history 2/week @ 2023-11-26 29/week @ 2023-12-03 34/week @ 2024-01-21 21/week @ 2024-01-28 36/week @ 2024-02-04 1/week @ 2024-02-11 4/week @ 2024-02-18 21/week @ 2024-02-25 4/week @ 2024-03-03

56 downloads per month
Used in 2 crates (via libflatterer)

Apache-2.0

45KB
916 lines

Yajlish - Rust event-based JSON parser

Write tools to parse json when you don't know its exact structure and can't load it all into memory.

  • based loosely on yajl
  • includes a JSON -> ndjson converter with the feature "ndjson"

boydjohnson

Docs

Libraries you probably need instead of this library

Usage

Suppose you wanted to parse the count of all JSON object keys that are named 'foo'.

     use yajlish::{Context, Handler, Status};

     pub struct FooCountHandler {
         count: usize,
     }

     impl Handler for FooCountHandler {
         
         fn handle_map_key(&mut self, _ctx: &Context, key: &str) -> Status {
             if key == "\"foo\"" {
                 self.count += 1;
             }
             Status::Continue
         }
     
         fn handle_null(&mut self, _ctx: &Context) -> Status {
             Status::Continue
         }

         fn handle_bool(&mut self, _ctx: &Context, boolean: bool) -> Status {
             Status::Continue
         }

         fn handle_double(&mut self, _ctx: &Context, val: f64) -> Status {
             Status::Continue
         }
         
         fn handle_int(&mut self, _ctx: &Context, val: i64) -> Status {
             Status::Continue
         }

         fn handle_string(&mut self, _ctx: &Context, val: &str) -> Status {
             Status::Continue
         }

         fn handle_start_map(&mut self, _ctx: &Context) -> Status {
             Status::Continue
         }
         
         fn handle_start_array(&mut self, _ctx: &Context) -> Status {
             Status::Continue
         }

         fn handle_end_map(&mut self, _ctx: &Context) -> Status {
             Status::Continue
         }

         fn handle_end_array(&mut self, _ctx: &Context) -> Status {
             Status::Continue
         }
     }

License

This library is licensed under the Apache 2.0 License.

Dependencies

~0–1MB