1# <small>nlohmann::basic_json::</small>front
2
3```cpp
4reference front();
5const_reference front() const;
6```
7
8Returns a reference to the first element in the container. For a JSON container `#!cpp c`, the expression
9`#!cpp c.front()` is equivalent to `#!cpp *c.begin()`.
10    
11## Return value
12
13In case of a structured type (array or object), a reference to the first element is returned. In case of number, string,
14boolean, or binary values, a reference to the value is returned.
15
16## Exception safety
17
18Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
19
20## Exceptions
21
22If the JSON value is `#!json null`, exception
23[`invalid_iterator.214`](../../home/exceptions.md#jsonexceptioninvalid_iterator214) is thrown.
24
25## Complexity
26
27Constant.
28
29## Notes
30
31!!! info "Precondition"
32
33    The array or object must not be empty. Calling `front` on an empty array or object yields undefined behavior.
34
35## Examples
36
37??? example
38
39    The following code shows an example for `front()`.
40     
41    ```cpp
42    --8<-- "examples/front.cpp"
43    ```
44    
45    Output:
46    
47    ```json
48    --8<-- "examples/front.output"
49    ```
50
51## See also
52
53- [back](back.md) to access the last element
54
55## Version history
56
57- Added in version 1.0.0.
58- Adjusted code to return reference to binary values in version 3.8.0.
59