Fix a few parsing bugs that can allow for truncation of valid JSON

Currently, the CFEngine JSON parser plays pretty fast and loose with the JSON spec. This minor change introduces some more intelligent sanity checking on the validity of the JSON structures being read in. I would like to make trailing commas cause an error per the JSON spec, but that tends to be much more divisive.

I'd also like to ask why you rolled your own JSON parser, rather than using one lik c-json or jansson?