Hello Mikrotik Support Team,
I am an official Mikrotik trainer, and I would like to report a bug related to the conversion of data structures to JSON in RouterOS.
Issue Description
When using the :serialize command to convert data structures to JSON in RouterOS, values that are originally strings containing numeric data (especially those starting with zero) are being incorrectly converted to float types. This results in the loss of information and alters the original data.
For instance, when extracting the system identity name configured as 0123, the conversion to JSON changes the value to 123.000000, removing the leading zero and changing the data type from string to float. This behavior is problematic as it alters the semantics of the data and can cause issues in integrations that rely on the accuracy and preservation of the original data type.
Steps to Reproduce
Set the device identity name to a numeric value starting with zero, such as 0123:
/system identity set name=0123
Retrieve the value using the command:
:put [/system/identity/get]
Convert the value to JSON using:
:put [:serialize value=[/system/identity/get] to=json];
Observe that the converted JSON value is altered to:
{"name":123.000000}
Expected Behavior
The original data type should be preserved in the JSON conversion. Strings containing numeric values should remain as strings in JSON, without removing leading zeros or converting them to floats. The expected output in this case should be {"name":"0123"}.
Environment
RouterOS Version: 7.16rc5
Device Model: CRS125-24G-1S-2HnD
Impact
This issue affects data integrity when using JSON for extraction or integration with other systems, particularly in cases where values such as PPP account names or identifiers with leading zeros are common.
Thank you for your attention to this matter. Please let me know if you need any additional information.
Best regards,
--
Ademir Vida