#define JSON_HAS_FILESYSTEM /* value */ #define JSON_HAS_EXPERIMENTAL_FILESYSTEM /* value */
When compiling with C++17, the library provides conversions from and to std::filesystem::path. As compiler support for filesystem is limited, the library tries to detect whether <filesystem>/std::filesystem (JSON_HAS_FILESYSTEM) or <experimental/filesystem>/std::experimental::filesystem (JSON_HAS_EXPERIMENTAL_FILESYSTEM) should be used. To override the built-in check, define JSON_HAS_FILESYSTEM or JSON_HAS_EXPERIMENTAL_FILESYSTEM to 1.
The default value is detected based on the preprocessor macros __cpp_lib_filesystem, __cpp_lib_experimental_filesystem, __has_include(<filesystem>), or __has_include(<experimental/filesystem>).
Known compiler/stdlib exclusions
Even when the feature-test macro indicates filesystem support is available, the library disables it on the following broken toolchains:
std::filesystem implementation; MinGW-w64 bug 737)If JSON_HAS_FILESYSTEM or JSON_HAS_EXPERIMENTAL_FILESYSTEM is 0 despite __cpp_lib_filesystem being defined, one of the exclusions above likely applies to your toolchain.
stdc++fs to be linked to for filesystem support.Example
The code below forces the library to use the header <experimental/filesystem>.
#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 #include <nlohmann/json.hpp> ...