lintel_validate/parsers/
json.rs1use miette::NamedSource;
2use serde_json::Value;
3
4use crate::diagnostics::ParseDiagnostic;
5
6use super::Parser;
7
8pub struct JsonParser;
9
10impl Parser for JsonParser {
11 fn parse(&self, content: &str, file_name: &str) -> Result<Value, ParseDiagnostic> {
12 serde_json::from_str(content).map_err(|e| {
13 let offset = super::line_col_to_offset(content, e.line(), e.column());
14 ParseDiagnostic {
15 src: NamedSource::new(file_name, content.to_string()),
16 span: offset.into(),
17 message: e.to_string(),
18 }
19 })
20 }
21
22 fn annotate(&self, content: &str, schema_url: &str) -> Option<String> {
23 Some(super::annotate_json_content(content, schema_url))
24 }
25
26 fn strip_annotation(&self, content: &str) -> String {
27 super::strip_json_schema_property(content)
28 }
29}