Skip to content

Error in JSON encoding #36

@larjohn

Description

@larjohn

I have received the following bug report recently:

http://apps.openbudgets.eu/cube/analytics/bonn-budget-2022-PSPelement__2603c/outlier_detection/LOF_FACTS?BABBAGE_FACT_URI=http%3A%2F%2Fapps.openbudgets.eu%2Fapi%2F3%2Fcubes%2Fbonn-budget-2022-PSPelement__2603c%2Ffacts%3F&coloringAttribute=fiscalYear.prefLabel&groupingAttribute=profitCenter.prefLabel
(return Error: 0)

http://apps.openbudgets.eu/cube/analytics/bonn-budget-2022-PSPelement__2603c/descriptive_statistics/facts?amounts=amount&dimensions=operationCharacter.prefLabel%7CprofitCenter.prefLabel%7CbusinessArea.prefLabel%7CeconomicClassification.prefLabel%7Corganization.organization&json_data=http%3A%2F%2Fapps.openbudgets.eu%2Fapi%2F3%2Fcubes%2Fbonn-budget-2022-PSPelement__2603c%2Ffacts%3F
(Error: lexical error: invalid char in json text. und Versicherungen","amount":NAN},{"operationCharacter.prefL (right here) ------^ In call: parse_con(txt, bigint_as_char))

It is caused by a NAN (not a number) being literally dumped as-is by PHP's json_encode function. NAN is a valid structure in PHP, but it has no valid meaning in a JSON serialization.

PHP docs state that there is a constant to provide as an option so that INF (infinity) and NAN (not a number) are substituted with zeros during the serialization. I tried the following chunk of code:

<?php
echo json_encode(["a" => INF, "b"=> NAN],JSON_ERROR_INF_OR_NAN |  JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_PRETTY_PRINT );
?>

In my local Windows PHP 7.0 installation, the above correctly resulted in {"a":0, "b":0}. In our docker image, INF was correctly converted to 0, but NAN remained as-is. I tried manually updating the php7 version in the running instance to PHP 7.1 and it worked correctly. It seems it was a bug and it got fixed.

While I could update PHP myself, this might result to some error driving the server out of order. So, @wk0206 can you or someone else just update the Rudolf docker image to a newer (7.1) version?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions