Skip to main content

Weight

The weight data structure is designed to represent the weight of an object in a standardized and easy-to-understand format. It consists of two fields: value and unit. The value field is a numerical representation of the object's weight, while the unit field denotes the unit of measurement for the weight.

FieldTypeDescription
massfloatThe numeric weight of the object. Must be a non-negative number.
unitstringThe unit of measurement for the weight. Should be a string representing a standard unit of weight, such as "kg" for kilograms, "lbs" for pounds, or "g" for grams.

Example

{
"mass": 1.5,
"unit": "kg"
}

In this example, the mass object represents a weight of 1.5 kilograms. The mass field is set to 1.5, and the unit field is set to "kg".

Usage Guidelines

  1. Ensure that the value field is always a non-negative number. Negative weight values are not valid and may cause unexpected results in calculations or comparisons.
  2. Use a consistent unit of measurement across all objects in your dataset. This will facilitate accurate comparisons, sorting, and calculations. If you need to store or display weights in multiple units, consider converting the values programmatically.
  3. When comparing or calculating weights, make sure to account for the unit of measurement. If necessary, convert the values to a common unit before performing any operations.
  4. When displaying the weight to users, consider formatting the output to include the unit of measurement for better readability, e.g., "1.5 kg" instead of just "1.5".