alamb commented on code in PR #5364: URL: https://github.com/apache/arrow-rs/pull/5364#discussion_r1477315835
########## arrow-json/src/writer.rs: ########## @@ -74,7 +74,35 @@ //! [`LineDelimitedWriter`] and [`ArrayWriter`] will omit writing keys with null values. //! In order to explicitly write null values for keys, configure a custom [`Writer`] by //! using a [`WriterBuilder`] to construct a [`Writer`]. - +//! +//! ## Writing to [serde_json] JSON Objects +//! +//! To serialize [`RecordBatch`]es into an array of +//! [JSON](https://docs.serde.rs/serde_json/) objects, use the [RawValue] api +//! +//! [RawValue]: https://docs.rs/serde_json/latest/serde_json/value/struct.RawValue.html +//! +//! ``` +//! # use std::sync::Arc; +//! # use arrow_array::{Int32Array, RecordBatch}; +//! # use arrow_schema::{DataType, Field, Schema}; +//! # use serde_json::{Map, Value}; +//! +//! let schema = Schema::new(vec![Field::new("a", DataType::Int32, false)]); +//! let a = Int32Array::from(vec![1, 2, 3]); +//! let batch = RecordBatch::try_new(Arc::new(schema), vec![Arc::new(a)]).unwrap(); +//! +//! let json_rows: Vec<Map<String, Value>> = todo!("How do we do this?"); Review Comment: Given I am still very confused about how the RawValue api fits in here (perhaps because as you hint, there is no clear usecase), I am going to remove mention from the docs to avoid confusion. I wonder if people potentially were using the `json_serde` values as an intermediate representation to map RecordBatches to their own data structures via `serde` 🤔 Maybe we can point them to the https://crates.io/crates/serde_arrow crate for that usecase 🤔 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
