alamb commented on code in PR #7862: URL: https://github.com/apache/arrow-rs/pull/7862#discussion_r2191079133
########## parquet-variant-json/src/from_json.rs: ########## @@ -0,0 +1,690 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! Module for parsing JSON strings as Variant + +use arrow_schema::ArrowError; +use parquet_variant::{ListBuilder, ObjectBuilder, Variant, VariantBuilder, VariantBuilderExt}; +use serde_json::{Number, Value}; + +/// Converts a JSON string to Variant using [`VariantBuilder`]. The resulting `value` and `metadata` +/// buffers can be extracted using `builder.finish()` +/// +/// # Arguments +/// * `json` - The JSON string to parse as Variant. +/// * `variant_builder` - Object of type `VariantBuilder` used to build the vatiant from the JSON +/// string +/// +/// # Returns +/// +/// * `Ok(())` if successful +/// * `Err` with error details if the conversion fails +/// +/// ```rust +/// # use parquet_variant::VariantBuilder; +/// # use parquet_variant_json::{ +/// # json_to_variant, variant_to_json_string, variant_to_json, variant_to_json_value +/// # }; +/// +/// let mut variant_builder = VariantBuilder::new(); +/// let person_string = "{\"name\":\"Alice\", \"age\":30, ".to_string() +/// + "\"email\":\"al...@example.com\", \"is_active\": true, \"score\": 95.7," +/// + "\"additional_info\": null}"; +/// json_to_variant(&person_string, &mut variant_builder)?; +/// +/// let (metadata, value) = variant_builder.finish(); +/// +/// let variant = parquet_variant::Variant::try_new(&metadata, &value)?; +/// +/// let json_result = variant_to_json_string(&variant)?; +/// let json_value = variant_to_json_value(&variant)?; +/// +/// let mut buffer = Vec::new(); +/// variant_to_json(&mut buffer, &variant)?; Review Comment: I agree they are useful in their own right, but I think it is pretty confusing to have json functionality split across two crates. I suggest we move all the JSON stuff to a new crate and we can always put to_json back if a need arises -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org