mapping_deduction.md

August 13, 2026 ยท View on GitHub

Many types can be deduced without being explicitly mapped to a JSON type (string, number, bool, object, or array). This allows one to use them directly in places that don't require a member name (e.g. a json_array element type) or with the json_link<Name, Type> mapping type. The first matching mapping is used, in the following order:

  • Types with an explicit json_data_contract specialization. An explicit mapping always takes precedence over any deduced mapping, including the default mapping for empty types.

  • Well known types

    TypeMapped ToNotes
    std:string_viewjson_string_raw
    std::stringjson_string
    booljson_bool
    Integerjson_numberUses std::numeric_limits. json_number optimized for Signed/Unsigned integers
    Enumjson_numberUsed std::is_enum and std::underlying_type
    Floating pointjson_numberUses std::numeric_limits
    Associative Containerjson_key_value_mapHas begin()/end()/key_type/mapped_type and constructable with two iterators
    readable valuesThe value_type in the readable mapping of T with a json_null wrapped around T's deduced mapping. See the readable value cookbook item
    Containersjson_arrayExcluding associative containers. Uses value_type as the type for each element
    Empty default-constructible typesEmpty JSON objectUsed only when no explicit mapping exists; serializes as {}
  • Containers - map to json_array with the element type as the detected type of the value_type. Must have the methods begin(), end(), type alias value_type, and can be constructed with two iterators. Same Iterator requirements as std:: vector's two iterator constructor.