openfoodfacts / openfoodfacts-server

Open Food Facts database, API server and web interface - 🐪🦋 Perl, CSS and JS coders welcome 😊 For helping in Python, see Robotoff or taxonomy-editor
GNU Affero General Public License v3.0
612 stars 358 forks source link

API nutriments inconsistency #639

Open aleene opened 7 years ago

aleene commented 7 years ago

The values of the nutriments in the json-api are inconsistent.

"saturated-fat_serving":0.26,"proteins_serving":7.67,"sugars_value":"1.7","energy_100g":"1546"

It should be made consistent. I guess it should be string, as it would allow the user to enter strings (such as "traces").

aleene commented 7 years ago

In fact it is more subtle. Products that are serving based, have _serving-fields as strings, but calculated _100g fields as strings as well: "fiber_serving":"0","sugars":"10","fat":"7","salt_100g":"2.05"

aleene commented 7 years ago

The _serving and the _100g values are sometimes calculated and sometimes not. Make this clear by creating a specific key postfix, i.e. _serving_calculated and 100g_calculated. These fields can then also be numbers.