Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible issue with Perl module JSON::XS #3

Open
MrPeanutButta opened this issue Dec 19, 2013 · 0 comments
Open

Possible issue with Perl module JSON::XS #3

MrPeanutButta opened this issue Dec 19, 2013 · 0 comments
Assignees

Comments

@MrPeanutButta
Copy link
Owner

Awaiting data on a JSON lib in Perl using JSON::XS having unexpected behavior when dealing with boolean true/false.

Related Issue:
http://stackoverflow.com/questions/6792173/in-perl-checking-a-json-decoded-boolean-value

Fix:
Consider using 1 or 0 for true/false

in bgp_api.cpp line 284

    if (entry->atomic_aggregate) {
        s_s << ",\"atomic_aggregate\":" << "true";
    } else {
        s_s << ",\"atomic_aggregate\":" << "false";
    }

CPAN
http://search.cpan.org/~mlehmann/JSON-XS-3.01/

use JSON;

sub ip_bgp{
    # Get IP Address from subroutine call
    my ( $vars ) = @_;
    my $ip = $vars->{'ip'};
    my $region = $vars->{'region'};
    my $return = {};

    #Assign API URI vars  
    my $api_uri1 = 'http://noc.' . $region . '.rackspace.net:4567/bgp/ipv4/' . $ip . '/history';
    my $api_request1 = LWP::UserAgent->new();
    $api_request1->default_header('pragma' => "no-cache", 'max-age' => '0');
    $api_request1->timeout(3);
    my $api_reply1 = $api_request1->get( $api_uri1 );

    #Error - API Request
    if ($api_reply1->is_error){
        $return->{'content'} = Dumper $api_reply1;
        $return->{'code'} = $api_reply1->code();
        return $return;
    }

    #Success - Gather Reply info
    if ($api_reply1->is_success){
        my $json1 = new JSON;
        my $json_data1 = $api_reply1->decoded_content;
        my $data1 = $json1->allow_nonref->utf8->relaxed->escape_slash->loose->allow_singlequote->allow_barekey->decode($json_data1);
        $return->{'content'} = $data1->{'entries'}[0];
        $return->{'code'} = 1;

        return $return;
    }
}
@MrPeanutButta MrPeanutButta added this to the bgpd v1.0.4 release milestone Feb 5, 2014
@MrPeanutButta MrPeanutButta self-assigned this Feb 5, 2014
@MrPeanutButta MrPeanutButta removed the bug label Jul 8, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant