[syslog-ng] [PATCH (3.4) 0/4]: json-parser updates
Gergely Nagy
algernon at balabit.hu
Tue Jan 10 13:11:05 CET 2012
Following this mail, a couple of patches will come - they were written
in last November, but I don't think I posted them (as I didn't expect
to see the json-parser merged so soon). Until now, they were sitting
on my feature/3.4/json/parser branch, and that's where they sit now,
too.
I rebased that branch onto 3.4 master + center.c syntax error fixes
(which I posted a week or two ago), and am sending the json parser
patches now.
They accomplish a few things: it makes the parser handle invalid JSON
input properly (by returning an error, instead of crashing); adds
support for parsing boolean, array and nested object types.
Booleans will get parsed into TRUE or FALSE, nested objects will be
turned into dotted notation (which also means that keys with a dot in
them won't be handled properly by format-json, once it is updated to
support reconstructing nested objects from dotted notation), and
arrays will be treated like nested objects, with the array indexes
used as a key.
As an example, lets look at a JSON input:
{"is-example": true,
"hats": ["top hat", "baseball cap", "pointy witch-hat"],
"auth": {
"method": ["looking angry at the security guy", "bribery"],
"result": "did not work"
}
}
This would be parsed into the following name-value paris:
"is-example"="TRUE"
"hats.0"="top hat"
"hats.1"="baseball cap"
"hats.2"="pointy witch-hat"
"auth.method.0"="looking angry at the security guy"
"auth.method.1"="bribery"
"auth.result"="did not work"
The other part of this will be an enhahcement to value-pairs and
format-json, that will make syslog-ng able to reconstruct the original
JSON (more or less... booleans probably won't be supported, except
perhaps optionally with a flag). But that is something I haven't
started working on yet.
More information about the syslog-ng
mailing list