use of org.graylog2.inputs.extractors.JsonExtractor in project graylog2-server by Graylog2.
the class JsonExtractorTest method testRunWithObjectAndDifferentKeySeparator.
@Test
public void testRunWithObjectAndDifferentKeySeparator() throws Exception {
final JsonExtractor jsonExtractor = new JsonExtractor(new MetricRegistry(), "json", "title", 0L, Extractor.CursorStrategy.COPY, "source", "target", ImmutableMap.<String, Object>of("key_separator", ":"), "user", Collections.<Converter>emptyList(), Extractor.ConditionType.NONE, "");
final String value = "{\"object\": {\"text\": \"foobar\", \"number\": 1234.5678, \"bool\": true, \"nested\": {\"text\": \"foobar\"}}}";
final Extractor.Result[] results = jsonExtractor.run(value);
assertThat(results).contains(new Extractor.Result("foobar", "object:text", -1, -1), new Extractor.Result(1234.5678, "object:number", -1, -1), new Extractor.Result(true, "object:bool", -1, -1), new Extractor.Result("foobar", "object:nested:text", -1, -1));
}
use of org.graylog2.inputs.extractors.JsonExtractor in project graylog2-server by Graylog2.
the class JsonExtractorTest method testRunWithArrayAndDifferentListSeparator.
@Test
public void testRunWithArrayAndDifferentListSeparator() throws Exception {
final JsonExtractor jsonExtractor = new JsonExtractor(new MetricRegistry(), "json", "title", 0L, Extractor.CursorStrategy.COPY, "source", "target", ImmutableMap.<String, Object>of("list_separator", ":"), "user", Collections.<Converter>emptyList(), Extractor.ConditionType.NONE, "");
final String value = "{\"array\": [\"foobar\", \"foobaz\"]}";
final Extractor.Result[] results = jsonExtractor.run(value);
assertThat(results).contains(new Extractor.Result("foobar:foobaz", "array", -1, -1));
}
use of org.graylog2.inputs.extractors.JsonExtractor in project graylog2-server by Graylog2.
the class JsonExtractorTest method testRunWithFlattenedObject.
@Test
public void testRunWithFlattenedObject() throws Exception {
final JsonExtractor jsonExtractor = new JsonExtractor(new MetricRegistry(), "json", "title", 0L, Extractor.CursorStrategy.COPY, "source", "target", ImmutableMap.<String, Object>of("flatten", true), "user", Collections.<Converter>emptyList(), Extractor.ConditionType.NONE, "");
final String value = "{" + "\"object\": {" + "\"text\": \"foobar\", " + "\"number\": 1234.5678, " + "\"bool\": true, " + "\"null\": null, " + "\"nested\": {\"text\": \"foobar\"}" + "}" + "}";
final Extractor.Result[] results = jsonExtractor.run(value);
assertThat(results).contains(new Extractor.Result("text=foobar, number=1234.5678, bool=true, nested={text=foobar}", "object", -1, -1));
}
Aggregations