use crate::row_batches::main::projection::projection;
use crate::row_batches::models::{JsonLayout, JsonRead, JsonReadSpec};
pub fn json_read_spec(text: &str, batch_rows: usize) -> Result<JsonRead, String> {
let spec: JsonReadSpec =
serde_json::from_str(text).map_err(|error| format!("fields: {error}"))?;
if spec.layout == JsonLayout::Lines && spec.path.is_some() {
return Err("path picks rows out of a JSON document; NDJSON has none".to_owned());
}
let projection = projection(spec.fields.as_deref(), spec.keep_record.as_deref())?;
Ok(JsonRead {
layout: spec.layout,
path: spec.path,
batch_rows,
projection,
})
}