1# <small>nlohmann::basic_json::</small>operator<
2
3```cpp
4// until C++20
5bool operator<(const_reference lhs, const_reference rhs) noexcept;   // (1)
6
7template<typename ScalarType>
8bool operator<(const_reference lhs, const ScalarType rhs) noexcept;  // (2)
9
10template<typename ScalarType>
11bool operator<(ScalarType lhs, const const_reference rhs) noexcept;  // (2)
12```
13
141. Compares whether one JSON value `lhs` is less than another JSON value `rhs` according to the
15  following rules:
16    - If either operand is discarded, the comparison yields `#!cpp false`.
17    - If both operands have the same type, the values are compared using their respective `operator<`.
18    - Integer and floating-point numbers are automatically converted before comparison.
19    - In case `lhs` and `rhs` have different types, the values are ignored and the order of the types
20      is considered, which is:
21        1. null
22        2. boolean
23        3. number (all types)
24        4. object
25        5. array
26        6. string
27        7. binary
28      For instance, any boolean value is considered less than any string.
29
302. Compares wether a JSON value is less than a scalar or a scalar is less than a JSON value by converting
31   the scalar to a JSON value and comparing both JSON values according to 1.
32
33## Template parameters
34
35`ScalarType`
36:   a scalar type according to `std::is_scalar<ScalarType>::value`
37
38## Parameters
39
40`lhs` (in)
41:   first value to consider 
42
43`rhs` (in)
44:   second value to consider 
45
46## Return value
47
48whether `lhs` is less than `rhs`
49
50## Exception safety
51
52No-throw guarantee: this function never throws exceptions.
53
54## Complexity
55
56Linear.
57
58## Notes
59
60!!! note "Comparing `NaN`"
61
62    `NaN` values are unordered within the domain of numbers.
63    The following comparisons all yield `#!cpp false`:
64      1. Comparing a `NaN` with itself.
65      2. Comparing a `NaN` with another `NaN`.
66      3. Comparing a `NaN` and any other number.
67
68!!! note "Operator overload resolution"
69
70    Since C++20 overload resolution will consider the _rewritten candidate_ generated from
71    [`operator<=>`](operator_spaceship.md).
72
73## Examples
74
75??? example
76
77    The example demonstrates comparing several JSON types.
78        
79    ```cpp
80    --8<-- "examples/operator__less.cpp"
81    ```
82    
83    Output:
84    
85    ```json
86    --8<-- "examples/operator__less.output"
87    ```
88
89## See also
90
91- [**operator<=>**](operator_spaceship.md) comparison: 3-way
92
93## Version history
94
951. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.
962. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.
97