mirror of
https://github.com/nlohmann/json.git
synced 2026-10-01 04:00:31 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ffc3691598 | ||
|
|
ec38da53eb | ||
|
|
30d5107b8d | ||
|
|
bdaa8381d7 | ||
|
|
85fec73da7 |
@@ -71,3 +71,38 @@ jobs:
|
||||
run: cmake --build build --parallel 10
|
||||
- name: Test
|
||||
run: cd build ; ctest -j 10 --output-on-failure
|
||||
|
||||
swiftpm:
|
||||
runs-on: macos-15
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Check that Package.swift resolves without a deprecation warning
|
||||
run: swift package dump-package
|
||||
- name: Build the SwiftPM documentation example against this checkout
|
||||
run: |
|
||||
mkdir -p /tmp/json-swiftpm-consumer/Sources/MyLibrary
|
||||
cp docs/mkdocs/docs/integration/swift/example.cpp /tmp/json-swiftpm-consumer/Sources/MyLibrary/example.cpp
|
||||
cat > /tmp/json-swiftpm-consumer/Package.swift << EOF
|
||||
// swift-tools-version: 5.9
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "MyPackage",
|
||||
dependencies: [
|
||||
.package(path: "${{ github.workspace }}")
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
name: "MyLibrary",
|
||||
dependencies: [
|
||||
.product(name: "json", package: "json")
|
||||
],
|
||||
publicHeadersPath: "."
|
||||
)
|
||||
]
|
||||
)
|
||||
EOF
|
||||
cd /tmp/json-swiftpm-consumer
|
||||
swift build
|
||||
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||
Upstream-Name: json
|
||||
Upstream-Contact: Niels Lohmann <mail@nlohmann.me>
|
||||
Source: https://github.com/nlohmann/json
|
||||
|
||||
Files: *
|
||||
Copyright: 2013-2026 Niels Lohmann <https://nlohmann.me>
|
||||
License: MIT
|
||||
|
||||
Files: include/nlohmann/thirdparty/hedley.hpp
|
||||
Copyright: 2016-2021 Evan Nemerson <evan@nemerson.com>
|
||||
License: CC0
|
||||
|
||||
Files: include/nlohmann/detail/meta/cpp_future.hpp
|
||||
Copyright: 2013-2026 Niels Lohmann <https://nlohmann.me> and 2018 The Abseil Authors
|
||||
License: MIT AND Apache-2.0
|
||||
|
||||
Files: tests/thirdparty/doctest/*
|
||||
Copyright: 2016-2023 Viktor Kirilov
|
||||
License: MIT
|
||||
|
||||
Files: tests/thirdparty/fifo_map/*
|
||||
Copyright: 2015-2017 Niels Lohmann
|
||||
License: MIT
|
||||
|
||||
Files: tests/thirdparty/Fuzzer/*
|
||||
Copyright: 2003-2022 LLVM Project.
|
||||
License: Apache-2.0
|
||||
|
||||
Files: tests/thirdparty/imapdl/*
|
||||
Copyright: 2017 Georg Sauthoff <mail@gms.tf>
|
||||
License: GPL-3.0-only
|
||||
|
||||
Files: tools/amalgamate/*
|
||||
Copyright: 2012 Erik Edlund <erik.edlund@32767.se>
|
||||
License: BSD-3-Clause
|
||||
|
||||
Files: tools/gdb_pretty_printer/*
|
||||
Copyright: 2020 Hannes Domani <https://github.com/ssbssa>
|
||||
License: MIT
|
||||
@@ -77,6 +77,7 @@ cc_library(
|
||||
name = "singleheader-json",
|
||||
hdrs = [
|
||||
"single_include/nlohmann/json.hpp",
|
||||
"single_include/nlohmann/json_fwd.hpp",
|
||||
],
|
||||
includes = ["single_include"],
|
||||
visibility = ["//visibility:public"],
|
||||
|
||||
+1
-1
@@ -10,5 +10,5 @@ title: "JSON for Modern C++"
|
||||
version: 3.12.0
|
||||
date-released: 2025-04-07
|
||||
license: MIT
|
||||
repository-code: "https://github.com/nlohmann"
|
||||
repository-code: "https://github.com/nlohmann/json"
|
||||
url: https://json.nlohmann.me
|
||||
|
||||
+4
-1
@@ -42,8 +42,11 @@ endif()
|
||||
## OPTIONS
|
||||
##
|
||||
|
||||
# Build the tests by default only for the main project and only if the tests
|
||||
# directory exists (the release archive json.tar.xz does not contain it).
|
||||
# VERSION_GREATER_EQUAL is not available in older CMake (< 3.7)
|
||||
if(${MAIN_PROJECT} AND (${CMAKE_VERSION} VERSION_EQUAL 3.13 OR ${CMAKE_VERSION} VERSION_GREATER 3.13))
|
||||
if(${MAIN_PROJECT} AND (${CMAKE_VERSION} VERSION_EQUAL 3.13 OR ${CMAKE_VERSION} VERSION_GREATER 3.13)
|
||||
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/CMakeLists.txt")
|
||||
set(JSON_BuildTests_INIT ON)
|
||||
else()
|
||||
set(JSON_BuildTests_INIT OFF)
|
||||
|
||||
@@ -207,19 +207,19 @@ Further documentation:
|
||||
|
||||
## REUSE
|
||||
|
||||
### `.reuse/dep5`
|
||||
### `REUSE.toml`
|
||||
|
||||
The file defines the licenses of certain third-party components in the repository. The root `Makefile` contains a target `reuse` that checks for compliance.
|
||||
|
||||
Further documentation:
|
||||
|
||||
- [DEP5](https://reuse.software/spec-3.2/#dep5-deprecated)
|
||||
- [REUSE.toml](https://reuse.software/spec-3.3/#reusetoml)
|
||||
- [reuse command-line tool](https://pypi.org/project/reuse/)
|
||||
- [documentation of linting](https://reuse.readthedocs.io/en/stable/man/reuse-lint.html)
|
||||
- [REUSE](http://reuse.software)
|
||||
|
||||
> [!IMPORTANT]
|
||||
> The filename `.reuse/dep5` is predetermined by REUSE. Alternatively, a `REUSE.toml` file can be used.
|
||||
> The filename `REUSE.toml` is predetermined by REUSE. Alternatively, a `.reuse/dep5` file (deprecated) can be used.
|
||||
|
||||
### `.reuse/templates`
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
# find GNU sed to use `-i` parameter
|
||||
SED:=$(shell command -v gsed || which sed)
|
||||
|
||||
# find GNU tar to use `--sort` and `--pax-option` parameters
|
||||
TAR:=$(shell command -v gtar || which tar)
|
||||
|
||||
|
||||
##########################################################################
|
||||
# source files
|
||||
@@ -215,8 +218,8 @@ ChangeLog.md:
|
||||
# archive is created according to the advices of <https://reproducible-builds.org/docs/archives/>.
|
||||
json.tar.xz:
|
||||
mkdir json
|
||||
rsync -R $(shell find LICENSE.MIT nlohmann_json.natvis CMakeLists.txt cmake/*.in include single_include -type f) json
|
||||
gtar --sort=name --mtime="@$(shell git log -1 --pretty=%ct)" --owner=0 --group=0 --numeric-owner --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime --create --file - json | xz --compress -9e --threads=2 - > json.tar.xz
|
||||
rsync -R $(shell find LICENSE.MIT nlohmann_json.natvis CMakeLists.txt cmake/*.in include single_include src/modules -type f) json
|
||||
$(TAR) --sort=name --mtime="@$(shell git log -1 --pretty=%ct)" --owner=0 --group=0 --numeric-owner --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime --create --file - json | xz --compress -9e --threads=2 - > json.tar.xz
|
||||
rm -fr json
|
||||
|
||||
# We use `-X` to make the resulting ZIP file reproducible, see
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import PackageDescription
|
||||
let package = Package(
|
||||
name: "nlohmann-json",
|
||||
platforms: [
|
||||
.iOS(.v12), .macOS(.v10_13), .tvOS(.v12), .watchOS(.v4), .visionOS(.v1)
|
||||
.iOS(.v12), .macOS(.v10_13), .tvOS(.v12), .watchOS(.v9), .visionOS(.v1)
|
||||
],
|
||||
products: [
|
||||
.library(name: "json", targets: ["json"])
|
||||
|
||||
@@ -1204,15 +1204,18 @@ language bindings, format converters, and the like. See the curated [Ecosystem](
|
||||
|
||||
Though it's 2026 already, the support for C++11 is still a bit sparse. Currently, the following compilers are known to work:
|
||||
|
||||
- GCC 4.8 - 14.2 (and possibly later)
|
||||
- Clang 3.4 - 21.0 (and possibly later)
|
||||
- Apple Clang 9.1 - 16.0 (and possibly later)
|
||||
- Intel C++ Compiler 17.0.2 (and possibly later)
|
||||
- Nvidia CUDA Compiler 11.0.221 (and possibly later)
|
||||
- Microsoft Visual C++ 2015 / Build Tools 14.0.25123.0 (and possibly later)
|
||||
- Microsoft Visual C++ 2017 / Build Tools 15.5.180.51428 (and possibly later)
|
||||
- Microsoft Visual C++ 2019 / Build Tools 16.3.1+1def00d3d (and possibly later)
|
||||
- Microsoft Visual C++ 2022 / Build Tools 19.30.30709.0 (and possibly later)
|
||||
- GCC 4.8 - 16.2 (and possibly later)
|
||||
- Clang 3.4 - 22.1 (and possibly later)
|
||||
- Apple Clang 15.0 - 21.0 (and possibly later)
|
||||
- Intel C++ Compiler Classic (icpc) 2021.10
|
||||
- Intel oneAPI DPC++/C++ Compiler (icpx) 2025.3 (and possibly later)
|
||||
- NVIDIA CUDA Compiler (nvcc) 11.8 - 12.6 (and possibly later)
|
||||
- NVIDIA HPC SDK C++ Compiler (nvc++) 25.5 (and possibly later)
|
||||
- Microsoft Visual C++ 2015 / MSVC 19.0 (and possibly later)
|
||||
- Microsoft Visual C++ 2017 / MSVC 19.16 (and possibly later)
|
||||
- Microsoft Visual C++ 2019 / MSVC 19.29 (and possibly later)
|
||||
- Microsoft Visual C++ 2022 / MSVC 19.44 (and possibly later)
|
||||
- Microsoft Visual C++ 2026 / MSVC 19.51 (and possibly later)
|
||||
|
||||
I would be happy to learn about other compilers/versions.
|
||||
|
||||
@@ -1402,7 +1405,7 @@ The library is compliant to version 3.3 of the [**REUSE specification**](https:/
|
||||
|
||||
- Every source file contains an SPDX copyright header.
|
||||
- The full text of all licenses used in the repository can be found in the `LICENSES` folder.
|
||||
- File `.reuse/dep5` contains an overview of all files' copyrights and licenses.
|
||||
- File `REUSE.toml` contains an overview of all files' copyrights and licenses.
|
||||
- Run `pipx run reuse lint` to verify the project's REUSE compliance and `pipx run reuse spdx` to generate a SPDX SBOM.
|
||||
|
||||
## Contact
|
||||
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
version = 1
|
||||
SPDX-PackageName = "json"
|
||||
SPDX-PackageSupplier = "Niels Lohmann <mail@nlohmann.me>"
|
||||
SPDX-PackageDownloadLocation = "https://github.com/nlohmann/json"
|
||||
|
||||
[[annotations]]
|
||||
path = "**"
|
||||
precedence = "aggregate"
|
||||
SPDX-FileCopyrightText = "2013-2026 Niels Lohmann <https://nlohmann.me>"
|
||||
SPDX-License-Identifier = "MIT"
|
||||
|
||||
[[annotations]]
|
||||
path = "include/nlohmann/thirdparty/hedley.hpp"
|
||||
precedence = "aggregate"
|
||||
SPDX-FileCopyrightText = "2016-2021 Evan Nemerson <evan@nemerson.com>"
|
||||
SPDX-License-Identifier = "CC0"
|
||||
|
||||
[[annotations]]
|
||||
path = "include/nlohmann/detail/meta/cpp_future.hpp"
|
||||
precedence = "aggregate"
|
||||
SPDX-FileCopyrightText = "2013-2026 Niels Lohmann <https://nlohmann.me> and 2018 The Abseil Authors"
|
||||
SPDX-License-Identifier = "MIT AND Apache-2.0"
|
||||
|
||||
[[annotations]]
|
||||
path = "tests/thirdparty/doctest/**"
|
||||
precedence = "aggregate"
|
||||
SPDX-FileCopyrightText = "2016-2023 Viktor Kirilov"
|
||||
SPDX-License-Identifier = "MIT"
|
||||
|
||||
[[annotations]]
|
||||
path = "tests/thirdparty/fifo_map/**"
|
||||
precedence = "aggregate"
|
||||
SPDX-FileCopyrightText = "2015-2017 Niels Lohmann"
|
||||
SPDX-License-Identifier = "MIT"
|
||||
|
||||
[[annotations]]
|
||||
path = "tests/thirdparty/Fuzzer/**"
|
||||
precedence = "aggregate"
|
||||
SPDX-FileCopyrightText = "2003-2022 LLVM Project."
|
||||
SPDX-License-Identifier = "Apache-2.0"
|
||||
|
||||
[[annotations]]
|
||||
path = "tests/thirdparty/imapdl/**"
|
||||
precedence = "aggregate"
|
||||
SPDX-FileCopyrightText = "2017 Georg Sauthoff <mail@gms.tf>"
|
||||
SPDX-License-Identifier = "GPL-3.0-only"
|
||||
|
||||
[[annotations]]
|
||||
path = "tools/amalgamate/**"
|
||||
precedence = "aggregate"
|
||||
SPDX-FileCopyrightText = "2012 Erik Edlund <erik.edlund@32767.se>"
|
||||
SPDX-License-Identifier = "BSD-3-Clause"
|
||||
|
||||
[[annotations]]
|
||||
path = "tools/gdb_pretty_printer/**"
|
||||
precedence = "aggregate"
|
||||
SPDX-FileCopyrightText = "2020 Hannes Domani <https://github.com/ssbssa>"
|
||||
SPDX-License-Identifier = "MIT"
|
||||
@@ -48,6 +48,7 @@ cc_library(
|
||||
name = "singleheader-json",
|
||||
hdrs = [
|
||||
"single_include/nlohmann/json.hpp",
|
||||
"single_include/nlohmann/json_fwd.hpp",
|
||||
],
|
||||
includes = ["single_include"],
|
||||
visibility = ["//visibility:public"],
|
||||
|
||||
@@ -64,7 +64,7 @@ if(MODE STREQUAL "undef")
|
||||
# recipe is self-contained and its output is byte-stable across reruns.
|
||||
# The embedded SPDX tags below are part of the *generated* file's
|
||||
# content, not a REUSE header for this .cmake script itself (which is
|
||||
# already covered by the blanket "Files: *" rule in .reuse/dep5) -- keep
|
||||
# already covered by the blanket path = "**" rule in REUSE.toml) -- keep
|
||||
# them wrapped in REUSE-IgnoreStart/End so `reuse lint` does not try to
|
||||
# parse "MIT\n")" as this file's own SPDX-License-Identifier value.
|
||||
# REUSE-IgnoreStart
|
||||
|
||||
@@ -115,4 +115,3 @@ The default value is `0` (disabled — existing behavior is preserved).
|
||||
## Version history
|
||||
|
||||
- Added in version 3.13.0.
|
||||
- Planned to become the default (with the macro removed) in version 4.0.0.
|
||||
|
||||
@@ -14,7 +14,7 @@ work items are tracked in the [GitHub milestones](https://github.com/nlohmann/js
|
||||
opt-in.
|
||||
- **Keep the 3.x public API stable.** Releases follow [semantic versioning](https://semver.org). Changes that would
|
||||
break existing code are only added behind a feature macro, so users can opt in and test their code before a next
|
||||
major release, see [Version 4.0](#version-40).
|
||||
major release.
|
||||
- **Support a broad range of compilers and platforms.** The [CI](quality_assurance.md) keeps testing old and new
|
||||
versions of GCC, Clang, MSVC, and other compilers on Linux, macOS, and Windows.
|
||||
- **Keep the quality assurance up.** Every change keeps the test coverage at 100%, passes the static and dynamic
|
||||
@@ -37,65 +37,7 @@ work items are tracked in the [GitHub milestones](https://github.com/nlohmann/js
|
||||
|
||||
## Version 4.0
|
||||
|
||||
There is no release date for version 4.0 yet. Proposals that need a major version, for instance stricter type
|
||||
conversions, are collected in issue [#3453](https://github.com/nlohmann/json/issues/3453).
|
||||
|
||||
!!! note "Not final"
|
||||
|
||||
The plan for version 4.0 described below is not final and may still change: macros may be added to or removed from
|
||||
the list, and planned defaults may be revised. Any such change will be documented on this page.
|
||||
|
||||
### Trying out 4.0 today
|
||||
|
||||
Version 4.0 will not be developed on a separate branch. Instead, every breaking change is first added to a 3.x release
|
||||
behind a macro whose default keeps the 3.x behavior. Version 4.0 then switches the defaults and removes the macros.
|
||||
Version 4.0 is therefore the sum of these macros: you can try it on the 3.x release train today by defining each macro
|
||||
to its 4.0 value and fixing what no longer compiles or behaves differently. Once your code works with all of them, it
|
||||
is ready for version 4.0.
|
||||
|
||||
The following macros guard changes that are planned to become the default in version 4.0:
|
||||
|
||||
| Macro | 3.x default | 4.0 behavior | CMake option | Added |
|
||||
|------------------------------------------------------------------------------------------------------------------|-------------|-------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------|--------|
|
||||
| [`JSON_USE_IMPLICIT_CONVERSIONS`](../api/macros/json_use_implicit_conversions.md) | `1` | `0`: no implicit conversions from `basic_json` to other types; use [`get`](../api/basic_json/get.md) instead | [`JSON_ImplicitConversions`](../integration/cmake.md#json_implicitconversions) | 3.9.0 |
|
||||
| [`JSON_USE_GLOBAL_UDLS`](../api/macros/json_use_global_udls.md) | `1` | `0`: the string literals `_json` and `_json_pointer` are only available in namespace `nlohmann::literals` | [`JSON_GlobalUDLs`](../integration/cmake.md#json_globaludls) | 3.11.0 |
|
||||
| [`JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON`](../api/macros/json_use_legacy_discarded_value_comparison.md) | `0` | removed: the deprecated legacy comparison of discarded values can no longer be enabled | [`JSON_LegacyDiscardedValueComparison`](../integration/cmake.md#json_legacydiscardedvaluecomparison) | 3.11.0 |
|
||||
| [`JSON_BRACE_INIT_COPY_SEMANTICS`](../api/macros/json_brace_init_copy_semantics.md) | `0` | `1`: single-element brace initialization such as `#!cpp json j{obj};` copies the element instead of creating an array | – | 3.13.0 |
|
||||
| [`JSON_PRECISE_STREAM_POSITION`](../api/macros/json_precise_stream_position.md) | `0` | `1`: reading from a stream does not consume the character after a number | – | 3.13.0 |
|
||||
| [`JSON_STRICT_NUL_HANDLING`](../api/macros/json_strict_nul_handling.md) | `0` | `1`: a NUL byte in the input is a parse error instead of the end of input | [`JSON_StrictNulHandling`](../integration/cmake.md#json_strictnulhandling) | 3.13.0 |
|
||||
|
||||
For example, the following makes a 3.x release behave like version 4.0 with respect to these changes:
|
||||
|
||||
```cpp
|
||||
#define JSON_USE_IMPLICIT_CONVERSIONS 0
|
||||
#define JSON_USE_GLOBAL_UDLS 0
|
||||
#define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 0
|
||||
#define JSON_BRACE_INIT_COPY_SEMANTICS 1
|
||||
#define JSON_PRECISE_STREAM_POSITION 1
|
||||
#define JSON_STRICT_NUL_HANDLING 1
|
||||
#include <nlohmann/json.hpp>
|
||||
```
|
||||
|
||||
The macros must be defined before the library header is included; setting them once in the build system is the easiest
|
||||
way to achieve this.
|
||||
|
||||
### Removal of deprecated functions
|
||||
|
||||
Version 4.0 will remove all deprecated functions. Compiling with deprecation warnings enabled shows which of them your
|
||||
code still uses. The [migration guide](../integration/migration_guide.md#replace-deprecated-functions) shows how to
|
||||
replace each of them.
|
||||
|
||||
| Deprecated | Since | Migration |
|
||||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------|----------------------------------------------------------------------------------|
|
||||
| `#!cpp operator<<(basic_json&, std::istream&)` | 3.0.0 | [Parsing](../integration/migration_guide.md#parsing) |
|
||||
| `#!cpp operator>>(const basic_json&, std::ostream&)` | 3.0.0 | [Miscellaneous functions](../integration/migration_guide.md#miscellaneous-functions) |
|
||||
| `iterator_wrapper` | 3.1.0 | [Miscellaneous functions](../integration/migration_guide.md#miscellaneous-functions) |
|
||||
| [`parse`](../api/basic_json/parse.md), [`accept`](../api/basic_json/accept.md), and [`sax_parse`](../api/basic_json/sax_parse.md) with an initializer list `{ptr, len}` or `{first, last}` | 3.8.0 | [Parsing](../integration/migration_guide.md#parsing) |
|
||||
| [`from_bson`](../api/basic_json/from_bson.md), [`from_cbor`](../api/basic_json/from_cbor.md), [`from_msgpack`](../api/basic_json/from_msgpack.md), and [`from_ubjson`](../api/basic_json/from_ubjson.md) with `(ptr, len)` or an initializer list | 3.8.0 | [Parsing](../integration/migration_guide.md#parsing) |
|
||||
| [`json_pointer::operator string_t`](../api/json_pointer/operator_string_t.md) | 3.11.0 | [JSON Pointers](../integration/migration_guide.md#json-pointers) |
|
||||
| [`json_pointer`](../api/json_pointer/index.md) with a `basic_json` type as template argument, and the overloads of `value`, `contains`, `operator[]`, and `at` accepting such a pointer | 3.11.0 | [JSON Pointers](../integration/migration_guide.md#json-pointers) |
|
||||
| Comparing a [`json_pointer`](../api/json_pointer/index.md) with a string via [`operator==`](../api/json_pointer/operator_eq.md) or [`operator!=`](../api/json_pointer/operator_ne.md) | 3.11.2 | [JSON Pointers](../integration/migration_guide.md#json-pointers) |
|
||||
|
||||
The deprecated legacy comparison of discarded values is controlled by a macro and therefore listed in the table above.
|
||||
|
||||
New breaking changes will follow the same path: they are added to these tables when they land in a 3.x release.
|
||||
There is no decision yet on whether or when a version 4.0 with breaking changes will be released. Proposals that need
|
||||
a major version, for instance stricter type conversions, are collected in issue
|
||||
[#3453](https://github.com/nlohmann/json/issues/3453). Until then, such changes are only added as opt-in behavior
|
||||
behind feature macros.
|
||||
|
||||
@@ -125,7 +125,7 @@ automatically download a release as a dependency at configure time.
|
||||
|
||||
### `JSON_BuildTests`
|
||||
|
||||
Build the unit tests when [`BUILD_TESTING`](https://cmake.org/cmake/help/latest/command/enable_testing.html) is enabled. This option is `ON` by default if the library's CMake project is the top project. That is, when integrating the library as described above, the test suite is not built unless explicitly switched on with this option.
|
||||
Build the unit tests when [`BUILD_TESTING`](https://cmake.org/cmake/help/latest/command/enable_testing.html) is enabled. This option is `ON` by default if the library's CMake project is the top project and the `tests` directory exists (the release archive `json.tar.xz` does not contain it). That is, when integrating the library as described above, the test suite is not built unless explicitly switched on with this option.
|
||||
|
||||
### `JSON_CI`
|
||||
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
# Migration Guide
|
||||
|
||||
This page collects some guidelines on how to future-proof your code for future versions of this library.
|
||||
The [roadmap](../community/roadmap.md#version-40) lists what will change in version 4.0, including the macros that let
|
||||
you try its behavior with a 3.x release; this page describes how to adjust your code.
|
||||
|
||||
## Replace deprecated functions
|
||||
|
||||
The following functions have been deprecated and will be removed in the next major version (i.e., 4.0.0), see the
|
||||
[roadmap](../community/roadmap.md#removal-of-deprecated-functions) for an overview. All
|
||||
The following functions have been deprecated and will be removed in the next major version (i.e., 4.0.0). All
|
||||
deprecations are annotated with
|
||||
[`HEDLEY_DEPRECATED_FOR`](https://nemequ.github.io/hedley/api-reference.html#HEDLEY_DEPRECATED_FOR) to report which
|
||||
function to use instead.
|
||||
@@ -37,9 +34,8 @@ function to use instead.
|
||||
[`accept`](../api/basic_json/accept.md), [`sax_parse`](../api/basic_json/sax_parse.md),
|
||||
[`from_cbor`](../api/basic_json/from_cbor.md), [`from_msgpack`](../api/basic_json/from_msgpack.md),
|
||||
[`from_ubjson`](../api/basic_json/from_ubjson.md), and [`from_bson`](../api/basic_json/from_bson.md) via initializer
|
||||
lists is deprecated since 3.8.0. The same holds for passing a pointer and a length as two arguments to the `from_*`
|
||||
functions. Instead, pass two iterators; for instance, call `from_cbor(ptr, ptr+len)` instead of
|
||||
`from_cbor({ptr, len})` or `from_cbor(ptr, len)`.
|
||||
lists is deprecated since 3.8.0. Instead, pass two iterators; for instance, call `from_cbor(ptr, ptr+len)` instead of
|
||||
`from_cbor({ptr, len})`.
|
||||
|
||||
=== "Deprecated"
|
||||
|
||||
|
||||
@@ -443,6 +443,30 @@ installed by adding the `-DJSON_MultipleHeaders=ON` flag (i.e., `cget install nl
|
||||
- :octicons-file-24: File issues at the [library issue tracker](https://github.com/nlohmann/json/issues)
|
||||
- :octicons-question-24: [Xcode documentation](https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app)
|
||||
|
||||
The `json` target's public headers live at `single_include/nlohmann`, so a consumer must write `#include <json.hpp>` rather than the
|
||||
`#include <nlohmann/json.hpp>` form used elsewhere in this documentation. The `json` target also ships only headers, and SwiftPM/Xcode
|
||||
expect every library target to produce an object file to link against; without one, linking a consumer fails with a missing `json.o`
|
||||
([#4650](https://github.com/nlohmann/json/issues/4650)). The workaround is to add at least one `.cpp` file of your own to the target
|
||||
that depends on `json`.
|
||||
|
||||
??? example
|
||||
|
||||
1. Create the following files:
|
||||
|
||||
```swift title="Package.swift"
|
||||
--8<-- "integration/swift/Package.swift"
|
||||
```
|
||||
|
||||
```cpp title="Sources/MyLibrary/example.cpp"
|
||||
--8<-- "integration/swift/example.cpp"
|
||||
```
|
||||
|
||||
2. Build
|
||||
|
||||
```shell
|
||||
swift build
|
||||
```
|
||||
|
||||
## NuGet
|
||||
|
||||
!!! abstract "Summary"
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// swift-tools-version: 5.9
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "MyPackage",
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/nlohmann/json.git", from: "3.12.0")
|
||||
],
|
||||
targets: [
|
||||
// the C++ target that uses nlohmann/json
|
||||
.target(
|
||||
name: "MyLibrary",
|
||||
dependencies: [
|
||||
.product(name: "json", package: "json")
|
||||
],
|
||||
// works around missing public headers in MyLibrary; not related to nlohmann/json
|
||||
publicHeadersPath: "."
|
||||
)
|
||||
]
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
// MyLibrary must contain at least one .cpp file, or SwiftPM/Xcode will
|
||||
// not build a usable "json" library to link against (see nlohmann/json#4650)
|
||||
#include <json.hpp>
|
||||
|
||||
nlohmann::json example()
|
||||
{
|
||||
return nlohmann::json::meta();
|
||||
}
|
||||
Reference in New Issue
Block a user