4.8. Strings vs. Numbers in API JSON

Strings vs Numbers in the IGSDB API JSON

When using the IGSDB API, you may notice that some numeric values are returned as strings instead of numbers. The IGSDB represents values where exact precision is important as strings to avoid issues with floating-point precision in JSON. Plain numbers in JSON are traditionally processed as floating-point values, which can lead to precision loss.

Internally, these values are stored in the IGSDB database as either Decimal fields or strings in JSON fields to preserve exact precision.

When you use the API, if you want all numeric values in a JSON response to be returned as actual numbers rather than strings -- perhaps for easier processing -- you can use the decimal_format=number query parameter in your API request. This will convert all numbers that would be returned as strings into numbers before returning the JSON response.

    
https://igsdb-v2.herokuapp.com/api/v2/glazing/products/?decimal_format=number
    

Side Note: IGDB/CGDB Ported Data

One of the most common values stored as strings in the IGSDB are the measured wavelength data values ( e.g. transmittance front, transmittance back, etc.). These values are provided by users and therefore the IGSDB uses strings to ensure that the measured values are preserved exactly as they were provided. This will be the standard process going forward as new product submission are submitted to the new and improved Checkertool application.

However, a complication arises due to the fact that currently the IGSDB is not populated by submission files via the Checkertool, but with information pulled directly from the IGDB and CGDB databases. In this case, exact user precision has been lost as the values are stored as double floating point values in those databases. Therefore, even though measured wavelength values are stored as strings, many products have values with large numbers of decimal places, as that is the complete double float value that was stored in the IGDB/CGDB.