Crates.io | streaming-json-completer |
lib.rs | streaming-json-completer |
version | 0.2.0-dev |
source | src |
created_at | 2023-05-05 13:50:51.34123 |
updated_at | 2023-05-05 14:05:52.876344 |
description | Complete JSON documents from a stream of JSON tokens |
homepage | https://github.com/genauai/streaming-json-completer |
repository | https://github.com/genauai/streaming-json-completer |
max_upload_size | |
id | 857735 |
size | 175,476 |
Streaming JSON Completer is a Rust library that helps you complete an incomplete JSON string by automatically adding the missing closing characters (quotes, braces, and brackets). This is particularly useful when you're dealing with streaming JSON data or working with partial JSON strings and need to ensure that the JSON is valid for further processing.
Add the following line to your Cargo.toml file under the [dependencies] section:
json-completer = "0.1.0"
Here's a basic example showing how to use the JSON Completer library:
use json_completer::complete_json;
fn main() {
let input = r#"{"key": "value", "arr": [1, 2, {"nested_key": "nested_value""#;
match complete_json(input) {
Ok(completion) => println!("The missing closing characters are: {}", completion),
Err(e) => println!("Error: {}", e),
}
}
For more examples and advanced usage, refer to the examples directory. In particular, the OpenAI Streaming Parse example shows how to use JSON Completer to parse a stream of JSON data from OpenAI's API (using 64bit's async-openai library).
To run the test suite for JSON Completer, simply run:
cargo test
This will execute a series of tests covering various scenarios, including nested objects and arrays, escaped quotes, and malformed JSON strings.
We welcome contributions! If you'd like to contribute, please follow these steps:
Please ensure that your code follows Rust's best practices and includes tests for any new functionality or bugfixes.
This project is licensed under the MIT License.