Page 1 of 1

problem with "false" in JSON output

Posted: Mon Apr 28, 2014 4:34 pm
by jssingh
Hi,

there is either a problem with the API JSON output for "false" or an issue with the decoder (I'm using the Perl library "JSON qw( decode_json )"). I noticed it today for one particular query and then checked another query with an output of "false" and the same issue exists.

Here is what it looks like if I just print out the JSON:

Code: Select all

$VAR1 = '{
  "format_version": 0,
  "result": {
    "query_time": 1398720372000,
    "cgi": "statusjson.cgi",
    "query": "downtimelist",
    "query_status": "beta",
    "program_start": 1398360977000,
    "last_data_update": 1398720367000,
    "type_code": 0,
    "type_text": "Success",
    "message": ""
  },
  "data": {
    "selectors": {
    },
    "downtimelist": {
      "4": {
        "downtime_id": 4,
        "type": "host",
        "host_name": "delta",
        "entry_time": 1398720121000,
        "start_time": 1398720094000,
        "flex_downtime_start": 0,
        "end_time": 1398727294000,
        "fixed": false,
        "triggered_by": 0,
        "duration": 7200,
        "is_in_effect": false,
        "start_notification_sent": false,
        "author": "author",
        "comment": "test"
      }
    }
  }
}
';
and this is after I decode it:

Code: Select all

$VAR1 = {
          'format_version' => 0,
          'data' => {
                      'downtimelist' => {
                                          '4' => {
                                                   'is_in_effect' => bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ),
                                                   'fixed' => $VAR1->{'data'}{'downtimelist'}{'4'}{'is_in_effect'},
                                                   'downtime_id' => 4,
                                                   'start_time' => '1398720094000',
                                                   'author' => 'author',
                                                   'duration' => 7200,
                                                   'start_notification_sent' => $VAR1->{'data'}{'downtimelist'}{'4'}{'is_in_effect'},
                                                   'end_time' => '1398727294000',
                                                   'comment' => 'test',
                                                   'triggered_by' => 0,
                                                   'flex_downtime_start' => 0,
                                                   'host_name' => 'delta',
                                                   'type' => 'host',
                                                   'entry_time' => '1398720121000'
                                                 }
                                        },
                      'selectors' => {}
                    },
          'result' => {
                        'query' => 'downtimelist',
                        'cgi' => 'statusjson.cgi',
                        'message' => '',
                        'query_status' => 'beta',
                        'program_start' => '1398360977000',
                        'type_text' => 'Success',
                        'type_code' => 0,
                        'query_time' => '1398720372000',
                        'last_data_update' => '1398720367000'
                      }
        };
Has anyone else seen this before? Can this be looked into?

thanks!

Re: problem with "false" in JSON output

Posted: Mon Apr 28, 2014 4:43 pm
by tmcdonald
Looks like they are ordering the elements differently, and one is using tabs while the other is using spaces. All the data seems to be the same.

Re: problem with "false" in JSON output

Posted: Mon Apr 28, 2014 4:52 pm
by jssingh
Hi,

yes, I am aware they are ordered differently, but when the output is false, it decodes weirdly. These are the specific variables:

Code: Select all

'is_in_effect' => bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' )

Code: Select all

'fixed' => $VAR1->{'data'}{'downtimelist'}{'4'}{'is_in_effect'}

Code: Select all

'start_notification_sent' => $VAR1->{'data'}{'downtimelist'}{'4'}{'is_in_effect'}
I would expect them to say:

Code: Select all

'is_in_effect' => false

Code: Select all

'fixed' => false

Code: Select all

'start_notification_sent' => false
(or 0 instead of "false")

Re: problem with "false" in JSON output

Posted: Mon Apr 28, 2014 5:03 pm
by tmcdonald
Does the perl library you are using expert a bool false or a string false? I'm not sure why it would output actual code in any case, but it could be a debug message that snuck in there.

Re: problem with "false" in JSON output

Posted: Mon Apr 28, 2014 5:33 pm
by jssingh
I'm sorry !! This is a problem with the Data::Dumper library. It's printing out weird stuff instead of true/false. I tried actually using the variable and it worked fine. ;)

Re: problem with "false" in JSON output

Posted: Tue Apr 29, 2014 9:11 am
by tmcdonald
Glad to see it working. Any victory over perl code is a good one. I'll be closing this thread now, but feel free to open another if you need anything in the future!