JsonToVariant

Trait JsonToVariant 

Source
pub trait JsonToVariant {
    // Required method
    fn append_json(&mut self, json: &str) -> Result<(), ArrowError>;
}
Expand description

Converts a JSON string to Variant using a [VariantBuilderExt], such as VariantBuilder.

The resulting value and metadata buffers can be extracted using builder.finish()

§Arguments

  • json - The JSON string to parse as Variant.

§Returns

  • Ok(()) if successful
  • Err with error details if the conversion fails

let mut variant_builder = VariantBuilder::new();
let person_string = "{\"name\":\"Alice\", \"age\":30, ".to_string()
+ "\"email\":\"alice@example.com\", \"is_active\": true, \"score\": 95.7,"
+ "\"additional_info\": null}";
variant_builder.append_json(&person_string)?;

let (metadata, value) = variant_builder.finish();

let variant = parquet_variant::Variant::try_new(&metadata, &value)?;

let json_result = variant.to_json_string()?;
let json_value = variant.to_json_value()?;

let mut buffer = Vec::new();
variant.to_json(&mut buffer)?;
let buffer_result = String::from_utf8(buffer)?;
assert_eq!(json_result, "{\"additional_info\":null,\"age\":30,".to_string() +
"\"email\":\"alice@example.com\",\"is_active\":true,\"name\":\"Alice\",\"score\":95.7}");
assert_eq!(json_result, buffer_result);
assert_eq!(json_result, serde_json::to_string(&json_value)?);

Required Methods§

Source

fn append_json(&mut self, json: &str) -> Result<(), ArrowError>

Create a Variant from a JSON string

Implementors§

Source§

impl<T: VariantBuilderExt> JsonToVariant for T