Skip to content

Commit ec7ea68

Browse files
committed
Update docs
1 parent 4f320ed commit ec7ea68

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

arrow-json/src/writer.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,8 @@
7878
//! ## Writing to [serde_json] JSON Objects
7979
//!
8080
//! To serialize [`RecordBatch`]es into an array of
81-
//! [JSON](https://docs.serde.rs/serde_json/) objects, use the [RawValue] api
82-
//!
83-
//! [RawValue]: https://docs.rs/serde_json/latest/serde_json/value/struct.RawValue.html
81+
//! [JSON](https://docs.serde.rs/serde_json/) objects you can reparse the resulting JSON string.
82+
//! Note that this is less efficient than using the `Writer` API.
8483
//!
8584
//! ```
8685
//! # use std::sync::Arc;
@@ -92,17 +91,22 @@
9291
//! let a = Int32Array::from(vec![1, 2, 3]);
9392
//! let batch = RecordBatch::try_new(Arc::new(schema), vec![Arc::new(a)]).unwrap();
9493
//!
95-
//! let json_rows: Vec<Map<String, Value>> = todo!("How do we do this?");
96-
//! // let json_rows = arrow_json::writer::record_batches_to_json_rows(&[&batch]).unwrap();
94+
//! // Write the record batch out as a JSON array
95+
//! let json_string = {
96+
//! let buf = Vec::new();
97+
//! let mut writer = arrow_json::ArrayWriter::new(buf);
98+
//! writer.write_batches(&vec![&batch]).unwrap();
99+
//! writer.finish().unwrap();
100+
//! String::from_utf8(writer.into_inner()).unwrap()
101+
//! };
102+
//!
103+
//! // Parse the string using serde_json
104+
//! let json_rows: Vec<Map<String, Value>> = serde_json::from_str(&json_string).unwrap();
97105
//! assert_eq!(
98106
//! serde_json::Value::Object(json_rows[1].clone()),
99107
//! serde_json::json!({"a": 2}),
100108
//! );
101109
//! ```
102-
//!
103-
//!
104-
//!
105-
//!
106110
mod encoder;
107111

108112
use std::iter;

0 commit comments

Comments
 (0)