* docs: new design for the documentation site Apply the brand to the Material for MkDocs site: Inter and JetBrains Mono served by the site (upright and real italic), brand colours, blue header band with the syntax pattern, wordmark in the header, new home page (hero, cards, animated feature tour), 404 page, polish for tabs, search, footer, focus rings, tables and code blocks, and theme features (code copy, previous/next footer, TOC follow, search suggestions). Draw the number railroad diagram, the parser callback events and the iterator illustrations as inline SVGs that follow the light and dark scheme. The generator scripts are in docs/mkdocs/scripts/figures; the feature slideshow (json-light.svg, json-dark.svg, replacing json.gif on the home page) is built by docs/mkdocs/scripts/slideshow. Decision nodes in five flowcharts become hexagons, which need far less room. Signed-off-by: Niels Lohmann <mail@nlohmann.me> * docs: add figures, table captions and a macro chooser - Figures with numbered captions: SAX stepper, json_view layout and edit stepper, exception map, JSON pointer and patch walkers, QA pipeline, scaling and binary size charts, roadmap lanes, release timeline, integration decision tree and namespace builder - Table captions (nj-table-caption) on 9 pages - Compile times: modules and PCH charts, filesystem section, re-measured Figure 1, links between features/modules.md and compile_times.md - Interactive macro chooser for features/arbitrary_types.md - Link check: exclude URLs that answer the plugin with 400/401/419 or are dead (customers.md) Signed-off-by: Niels Lohmann <mail@nlohmann.me> * docs: macro chooser generates adl_serializer for non-default-constructible types Signed-off-by: Niels Lohmann <mail@nlohmann.me> * docs: cross-link concept pages and API pages in See also sections Add See also links in both directions between the concept pages (features, home, integration) and the API pages, write API links in code font, give every entry a comment after a dash, and show the callback event figure on the parser callbacks page. Signed-off-by: Niels Lohmann <mail@nlohmann.me> * docs: address review comments on the new design - Home: add a "Latest release" button - Sponsors: update the list and group it by tier - Features: list all feature pages on the index page - Releases: add highlights per release, link the 4.0 roadmap, add the first commit to the timeline - Exceptions: prefix all example messages with the exception name - API: no code font for format names in the See also links of the to_/from_ pages - Merge Patch: show the document before, the patch, and the result - Replace "--" with typographic dashes, mark external links with an icon, center Mermaid diagrams Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me>
7.6 KiB
nlohmann::basic_json_view
Defined in header <nlohmann/json_view.hpp>
template<typename BasicJsonType, view_mode Mode = view_mode::read_only>
class basic_json_view;
A read-only handle to one value of a basic_json_document: two pointers (a pointer
to the document and a pointer into its index), trivially copyable. A view is valid as long as
- the document is alive,
- the document has not been re-parsed with
read()(orparse()into it) or shrunk withshrink_to_fit()since the view was taken, and - if the document borrows its source text, that text is still alive and unmodified (floating-point values and unescaped strings are read from it lazily).
Moving the document itself does not invalidate its views: the index is heap-allocated independently of the
basic_json_document object.
basic_json_view provides the read-only part of the BasicJsonType interface:
- the type-inspection functions
- element access
- lookup
- iteration
- conversion:
get<T>(),get_string(),number_token(), andmaterialize()to build theBasicJsonTypevalue of a subtree on demand - comparison:
operator==andoperator!=compare two views, or a view and aBasicJsonTypevalue, without ever building aBasicJsonTypevalue for a view; no ordering comparison (#!cpp operator<) is provided
operator[], at, contains, and value also accept a
json_pointer. Unlike basic_json, there are no implicit conversion operators (no
#!cpp operator ValueType()), and no #!cpp get_ptr() or #!cpp get_ref(); see get.
basic_json_view itself is always read-only — it never has a set or push_back of its own. A view of an
editable document (#!cpp view_mode::editable) sees every edit made through
basic_json_document::set and
basic_json_document::push_back: once a value is changed, every view that
still refers to it — including ones taken before the change — reads the new value. See
Edits.
Template parameters
BasicJsonType- a specialization of
basic_json, matching thebasic_json_documentthe view was taken from. Mode- a
view_mode: whether the view is of an editable document, matching thebasic_json_documentit was taken from (optional,#!cpp view_mode::read_onlyby default). See Edits.
Specializations
- json_view - views of a
json_document - ordered_json_view - views of an
ordered_json_document - json_editable_view - views of a
json_editable_document - ordered_json_editable_view - views of an
ordered_json_editable_document
Member types
- basic_json_type -
BasicJsonType(it also marks the class foris_json_view) - value_t - the JSON type enumeration, see
basic_json::value_t - string_t, number_integer_t, number_unsigned_t, number_float_t, json_pointer - the corresponding
member types of
BasicJsonType - size_type -
#!cpp std::size_t - string_view_t -
#!cpp std::string_viewon C++17 and newer, a minimal internal substitute otherwise - iterator, const_iterator - a forward iterator over the elements of an array or the member values of an object, in document order; both names refer to the same type, since a view is always read-only
- number_format - how
dump()writes numbers
Member functions
Object inspection
- type - return the type of the value
- type_name - return the type as string
- is_null - return whether the value is null
- is_boolean - return whether the value is a boolean
- is_number - return whether the value is a number
- is_number_integer - return whether the value is an integer number
- is_number_unsigned - return whether the value is an unsigned integer number
- is_number_float - return whether the value is a floating-point number
- is_string - return whether the value is a string
- is_array - return whether the value is an array
- is_object - return whether the value is an object
- is_binary - return whether the value is a binary array (always
#!cpp false) - is_primitive - return whether the type is primitive
- is_structured - return whether the type is structured
- is_discarded - return whether the view is invalid
Element access
- at - access specified element with bounds checking
- operator[] - access specified element
- value - access specified element with default value
- front - access the first element
- back - access the last element
Lookup
- find - find an element in an object
- count - returns the number of occurrences of a key in an object
- contains - check the existence of an element in an object
Iterators
- begin - returns an iterator to the first element
- cbegin - returns a const iterator to the first element
- end - returns an iterator to one past the last element
- cend - returns a const iterator to one past the last element
- items - wrapper to access iterator member functions in range-based for
Capacity
Conversion
- get - get a value
- get_to - get a value and write it to a destination
- get_string - get a string value without a copy
- number_token - get a number's token text without a copy
- materialize - build the
BasicJsonTypevalue of this subtree
Comparison
- operator== - comparison: equal
- operator!= - comparison: not equal
Serialization
- dump - serialize to a JSON-formatted string
- operator<< - serialize to stream
Source access
- source_offset - byte offset of this value in the document's source text
See also
- Zero-copy JSON views - guide to documents and views
basic_json_document- the document that owns the parsed datajson_view- andjson_editable_view- the default specializationsmaterialize- build abasic_jsonvalue from a view
Version history
- Added in version 3.13.0.