Zabbix provides some json parsing functions (see zbxjson.h):
How can I use these functions for parsing this JSON (Docker JSON API output):
A few tests:
zbx_json_object_is_empty: -1 -> OK, json is not empty
zbx_json_count: 3 -> OK, we have 3 json objects there, I want to iterate through these objects
zbx_json_open: cannot parse as a valid JSON object: invalid object format, expected opening character '{' at: '[{"Command".....
I've checked zabbix source codes, but no success.
Code:
int zbx_json_open(const char *buffer, struct zbx_json_parse *jp); const char *zbx_json_next(const struct zbx_json_parse *jp, const char *p); const char *zbx_json_next_value(const struct zbx_json_parse *jp, const char *p, char *string, size_t len, int *is_null); const char *zbx_json_next_value_dyn(const struct zbx_json_parse *jp, const char *p, char **string, size_t *string_alloc, int *is_null); const char *zbx_json_pair_next(const struct zbx_json_parse *jp, const char *p, char *name, size_t len); const char *zbx_json_pair_by_name(const struct zbx_json_parse *jp, const char *name); int zbx_json_value_by_name(const struct zbx_json_parse *jp, const char *name, char *string, size_t len); int zbx_json_value_by_name_dyn(const struct zbx_json_parse *jp, const char *name, char **string, size_t *string_alloc); int zbx_json_brackets_open(const char *p, struct zbx_json_parse *out); int zbx_json_brackets_by_name(const struct zbx_json_parse *jp, const char *name, struct zbx_json_parse *out); int zbx_json_object_is_empty(const struct zbx_json_parse *jp); int zbx_json_count(const struct zbx_json_parse *jp);
Code:
[{"Command":"/bin/docker-zabbix run","Created":1425672492,"Id":"ba52fb59230e2767ef04ff9209b8767801b80cd182447f68186af37c9998ec93","Image":"berngp/docker-zabbix:latest","Names":["/zabbix4"],"Ports":[{"IP":"0.0.0.0","PrivatePort":80,"PublicPort":49167,"Type":"tcp"},{"IP":"0.0.0.0","PrivatePort":10051,"PublicPort":49168,"Type":"tcp"},{"IP":"0.0.0.0","PrivatePort":10052,"PublicPort":49165,"Type":"tcp"},{"IP":"0.0.0.0","PrivatePort":2812,"PublicPort":49166,"Type":"tcp"}],"Status":"Up 14 hours"}
,{"Command":"/bin/docker-zabbix run","Created":1425672488,"Id":"7f175c4c9e0efd03b4a5823d922f13e57796fc592441f484196bed5297036cc2","Image":"berngp/docker-zabbix:latest","Names":["/zabbix3"],"Ports":[{"IP":"0.0.0.0","PrivatePort":10051,"PublicPort":49161,"Type":"tcp"},{"IP":"0.0.0.0","PrivatePort":10052,"PublicPort":49162,"Type":"tcp"},{"IP":"0.0.0.0","PrivatePort":2812,"PublicPort":49163,"Type":"tcp"},{"IP":"0.0.0.0","PrivatePort":80,"PublicPort":49164,"Type":"tcp"}],"Status":"Up 14 hours"}
,{"Command":"/bin/docker-zabbix run","Created":1425604740,"Id":"d5bf68ec1fb570d8ac3047226397edd8618eed14278ce035c98fbceef02d7730","Image":"berngp/docker-zabbix:latest","Names":["/zabbix2"],"Ports":[{"IP":"0.0.0.0","PrivatePort":80,"PublicPort":49157,"Type":"tcp"},{"IP":"0.0.0.0","PrivatePort":10051,"PublicPort":49158,"Type":"tcp"},{"IP":"0.0.0.0","PrivatePort":10052,"PublicPort":49159,"Type":"tcp"},{"IP":"0.0.0.0","PrivatePort":2812,"PublicPort":49160,"Type":"tcp"}],"Status":"Up 33 hours"}
]
zbx_json_object_is_empty: -1 -> OK, json is not empty
zbx_json_count: 3 -> OK, we have 3 json objects there, I want to iterate through these objects
zbx_json_open: cannot parse as a valid JSON object: invalid object format, expected opening character '{' at: '[{"Command".....
I've checked zabbix source codes, but no success.
Comment