[collectd] [PATCH] utils_format_json: serialize nan and inf as null, as per JSON spec

Florian Forster octo at verplant.org
Thu Feb 4 10:20:07 CET 2010

Hi Chris,

On Thu, Feb 04, 2010 at 12:52:30AM -0800, Chris Buben wrote:
> I'm deserializing JSON output from the write_http plugin using ruby-yajl.
> yajl was puking on the literal value nan encoded in the output.

thanks for your patch :) I think it's kind of weird that JSON doesn't
differentiate between -inf, inf and nan, but since that's what the
standard says, that's what we should be doing.

> -      BUFFER_ADD ("%g", vl->values[i].gauge);
> +    {
> +      if(isnan(vl->values[i].gauge) || isinf(vl->values[i].gauge))
> +        BUFFER_ADD ("null");
> +      else
> +        BUFFER_ADD ("%g", vl->values[i].gauge);
> +    }

I'm a bit uncomfortable using "isinf" here. We've had a great deal of
trouble with "isnan". Since "isinf" isn't used anywhere else and the C99
standard says it is a macro, I'll change this to:

  #ifdef isinf
    if (isnan (value) || isinf (value))
    if (isnan (value))

Does this sound alright to you?

Florian octo Forster
Hacker in training
GnuPG: 0x91523C3D
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20100204/9a433675/attachment.pgp 

More information about the collectd mailing list