pub struct JsonEdit {
pub json: String,
pub program: String,
pub pretty_output: bool,
}Expand description
The processor configuration.
Fields§
§json: StringThe JSON string that will be parsed by the program value.
program: StringThe program to run against the provided json string.
A program can either filter the JSON down to a subset of data, or can mutate the data before returning a value.
To learn about the supported syntax, see the jq documentation:
https://stedolan.github.io/jq/manual/v1.6/
pretty_output: bool“Pretty print” the JSON output.
If set to false, the JSON will be printed in a compact format, without any indentation, spacing or newlines.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for JsonEdit
impl<'de> Deserialize<'de> for JsonEdit
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<'a> Processor<'a> for JsonEdit
impl<'a> Processor<'a> for JsonEdit
Source§fn validate(&self) -> Result<(), Self::Error>
fn validate(&self) -> Result<(), Self::Error>
Validate that the provided program syntax is valid.
§Errors
If the program contains invalid syntax, the Error::Json error
variant is returned.
Source§fn run(&self, _context: &Context) -> Result<Option<Self::Output>, Self::Error>
fn run(&self, _context: &Context) -> Result<Option<Self::Output>, Self::Error>
Run the provided program against the json data.
§Output
If the final output is a string, the surrounding JSON quotes are removed. This makes it easier to show raw strings in the UI, without having to use the regex processor to remove extra quotes.
This output:
"world"Becomes this:
worldIf pretty_output is set, any JSON object or array is pretty printed,
by including newlines, indentation and spacing around the key/value
pairs.
This output:
{"hello":"world"}Becomes this:
{
"hello": "world"
}When unwrapping arrays in the program, each line is processed according to the above rules.
So this output:
[{"hello":"world"},"hello",2]Becomes this:
{"hello":"world"}
hello
2When using the program .[].
§Errors
This method returns the Error::Json error variant if the provided
json input or the program has invalid syntax.
The Error::Serde error variant is returned if the processor failed
to serialize or deserialize the input/output JSON.