MongoDB C++ Driver mongocxx-4.0.0
Loading...
Searching...
No Matches
json.hpp
Go to the documentation of this file.
1// Copyright 2009-present MongoDB, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <string>
18
19#include <bsoncxx/json-fwd.hpp>
20
25
27
28namespace bsoncxx {
29namespace v_noabi {
30
33enum class ExtendedJsonMode : std::uint8_t {
34 k_legacy,
36 k_relaxed,
37};
38
52
53BSONCXX_ABI_EXPORT_CDECL(std::string)
54to_json(document::view view, ExtendedJsonMode mode = ExtendedJsonMode::k_legacy);
55
58
61
71BSONCXX_ABI_EXPORT_CDECL(document::value) from_json(stdx::string_view json);
72
85BSONCXX_ABI_EXPORT_CDECL(document::value) operator"" _bson(const char* json, size_t len);
86
87} // namespace v_noabi
88} // namespace bsoncxx
89
90namespace bsoncxx {
91
92using ::bsoncxx::v_noabi::from_json;
93using ::bsoncxx::v_noabi::to_json;
94
95using ::bsoncxx::v_noabi::operator"" _bson;
96
97} // namespace bsoncxx
98
100
105
106#if defined(BSONCXX_PRIVATE_DOXYGEN_PREPROCESSOR)
107
108namespace bsoncxx {
109
112 v_noabi::ExtendedJsonMode mode = ExtendedJsonMode::k_legacy);
113
116 v_noabi::ExtendedJsonMode mode = ExtendedJsonMode::k_legacy);
117
120
121// Space is required between `operator` and `""` in @ref to avoid confusing Doxygen.
123v_noabi::document::value operator""_bson(const char* json, std::size_t len);
124
125} // namespace bsoncxx
126
127#endif // defined(BSONCXX_PRIVATE_DOXYGEN_PREPROCESSOR)
Provides bsoncxx::v_noabi::array::view.
The bsoncxx macro guard postlude header.
The bsoncxx macro guard prelude header.
A read-only, non-owning view of a BSON document.
Definition view.hpp:36
A read-only BSON document that owns its underlying buffer. When a document::value goes out of scope,...
Definition value.hpp:38
A read-only, non-owning view of a BSON document.
Definition view.hpp:35
A polyfill for std::string_view.
Definition string_view.hpp:436
Provides bsoncxx::v_noabi::document::value.
Provides bsoncxx::v_noabi::document::view.
#define BSONCXX_ABI_EXPORT_CDECL(...)
Equivalent to BSONCXX_ABI_EXPORT with BSONCXX_ABI_CDECL.
Definition fwd.hpp:177
Declares bsoncxx::v_noabi::ExtendedJsonMode.
std::string to_json(document::view view, ExtendedJsonMode mode=ExtendedJsonMode::k_legacy)
Converts a BSON document to a JSON string, in extended format.
ExtendedJsonMode
An enumeration of the types of Extended JSON that the to_json function accepts.
Definition json.hpp:33
@ k_relaxed
to produce Relaxed Extended JSON
@ k_legacy
to produce Legacy Extended JSON
@ k_canonical
to produce Canonical Extended JSON
document::value from_json(stdx::string_view json)
Constructs a new document::value from the provided JSON text.
The top-level namespace within which all bsoncxx library entities are declared.
std::string to_json(v_noabi::document::view view, v_noabi::ExtendedJsonMode mode=ExtendedJsonMode::k_legacy)
bsoncxx::v_noabi::to_json(v_noabi::document::view view, v_noabi::ExtendedJsonMode mode)
v_noabi::document::value from_json(v_noabi::stdx::string_view json)
bsoncxx::v_noabi::from_json(v_noabi::stdx::string_view json)
The top-level namespace reserved for the C++ standard library.
Provides std::optional-related polyfills for library API usage.