xdot JSON output is not valid JSON
Steps to reproduce
Compile and run the following program:
// simple test case of turning an xdot command into JSON
#include <assert.h>
#include <graphviz/xdot.h>
#include <stdio.h>
#include <stdlib.h>
int main(void) {
// xdot input
static const char input[] =
"c 9 -#fffffe00 C 7 -#ffffff P 4 0 0 0 36 54 36 54 0 ";
// parse it into an xdot object
xdot *x = parseXDot((char*)input);
assert(x != NULL);
// turn that into JSON
jsonXDot(stdout, x);
// clean up
freeXDot(x);
return EXIT_SUCCESS;
}
Expected Behaviour
Valid JSON printed to stdout.
Actual Behaviour
[
{c : "#fffffe00"},
{C : "#ffffff"},
{P : [0.000000,0.000000,0.000000,36.000000,54.000000,36.000000,54.000000,0.000000]}
]
OS Version
Debian 10.2
Graphviz Version
Commit 2b408883
Additional info
The problem is things like c
, C
, and P
that are invalid JSON. The right way to do this would be to wrap these in quotes so they were strings. This stems from jsonXDot_Op
in lib/xdot/xdot.c.
I don't know quite what to make of this, because this clearly isn't a typo but intentional. Is this not the expected way to use xdot? The resulting "JSON" like this cannot be consumed by, e.g., Python.