A YAML parser and emitter in C++

yaml-cpp Build Status Documentation

yaml-cpp is a YAML parser and emitter in C++ matching the YAML 1.2 spec.

To get a feel for how it can be used, see the Tutorial or How to Emit YAML. For the old API (version < 0.5.0), see How To Parse A Document.

Problems?

If you find a bug, post an issue! If you have questions about how to use yaml-cpp, please post it on http://stackoverflow.com and tag it yaml-cpp.

How to Build

yaml-cpp uses CMake to support cross-platform building. The basic steps to build are:

  1. Download and install CMake (Resources -> Download).

Note: If you don't use the provided installer for your platform, make sure that you add CMake's bin folder to your path.

  1. Navigate into the source directory, and type:
mkdir build
cd build
  1. Run CMake. The basic syntax is:
cmake [-G generator] [-DYAML_BUILD_SHARED_LIBS=ON|OFF] ..
  • The generator is whatever type of build system you'd like to use. To see a full list of generators on your platform, just run cmake (with no arguments). For example:

    • On Windows, you might use "Visual Studio 12 2013" to generate a Visual Studio 2013 solution or "Visual Studio 14 2015 Win64" to generate a 64-bit Visual Studio 2015 solution.
    • On OS X, you might use "Xcode" to generate an Xcode project
    • On a UNIX-y system, simply omit the option to generate a makefile
  • yaml-cpp defaults to building a static library, but you may build a shared library by specifying -DYAML_BUILD_SHARED_LIBS=ON.

  • For more options on customizing the build, see the CMakeLists.txt file.

  1. Build it!

  2. To clean up, just remove the build directory.

Recent Release

yaml-cpp 0.6.0 has been released! This release requires C++11, and no longer depends on Boost.

yaml-cpp 0.3.0 is still available if you want the old API.

The old API will continue to be supported, and will still receive bugfixes! The 0.3.x and 0.4.x versions will be old API releases, and 0.5.x and above will all be new API releases.

API Documentation

The autogenerated API reference is hosted on CodeDocs

Third Party Integrations

The following projects are not officially supported:

Comments
  • Add support for merge keys.

    Add support for merge keys.

    This would close issue #41. While the merge key type isn't mentioned in the YAML 1.2 spec, there's a spec for YAML 1.1, and I know I'm not alone in finding it a very useful feature.

  • Deprecating boost and implementing C++11 support

    Deprecating boost and implementing C++11 support

    Requiring the adoption of the boost libraries so as to use yaml-cpp is 
    problematic for many developers.
    
    Given that the C++11 standard library now includes all the features yaml-cpp 
    currently uses from boost, it would be good to deprecate the use of boost in 
    favour of C++11.
    
    

    Original issue reported on code.google.com by [email protected] on 12 Nov 2014 at 3:03

  • Expose precision control for float/double output

    Expose precision control for float/double output

    Hello!
    
    I have been using yaml-cpp in a project (OpenColorIO), and we just switched 
    from svn r423 to r482.   As part of our file format, we often write out a lot 
    of 32-bit floats and we noticed that at some point recently yaml-cpp started 
    forcing 15 digits of precision on numerical outputs.  (See src/emitter.cpp : 
    line 661).   While this makes sense for double values, it's not always 
    preferable for float types, as most of the right-most digits will be garbage.
    
    Example: 6.01 -> 6.01000022888184
    
    I'm not sure what the best solutions is, possibilities include:
    * using a type-aware precision
    * Allowing the user to control the precision explicitly (A new flow control 
    type?)
    
    But it would probably make sense to allow for some control of the issue. We're 
    using yaml files to allow for 'pretty' output, and this runs counter to that 
    philosophy.
    
    Thanks!
    

    Original issue reported on code.google.com by [email protected] on 17 May 2011 at 11:20

  • Cannot find headers (and libraries) as CMake variables are unset

    Cannot find headers (and libraries) as CMake variables are unset

    Hello,

    as per issue title, I'm having a problem when I try to use yaml-cpp in a project I'm working on. Namely, the compiler can't find header files (but I suppose the same will go for libraries) when I try to compile.

    This is due to the fact that the file used by CMake to set the paths of include and link directories does not set the proper values for the variables. The content of share/cmake/yaml-cpp/yaml-cpp-config.cmake after installation is;:

    # - Config file for the yaml-cpp package
    # It defines the following variables
    #  YAML_CPP_INCLUDE_DIR - include directory
    #  YAML_CPP_LIBRARIES    - libraries to link against
    
    # Compute paths
    get_filename_component(YAML_CPP_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
    set(YAML_CPP_INCLUDE_DIR "")
    
    # Our library dependencies (contains definitions for IMPORTED targets)
    include("${YAML_CPP_CMAKE_DIR}/yaml-cpp-targets.cmake")
    
    # These are IMPORTED targets created by yaml-cpp-targets.cmake
    set(YAML_CPP_LIBRARIES "")
    

    As you can see, the variables YAML_INCLUDE_DIR and YAML_CPP_LIBRARIES are empty. I believe the problem may lie in the input file yaml-cpp-config.cmake.in:

    # - Config file for the yaml-cpp package
    # It defines the following variables
    #  YAML_CPP_INCLUDE_DIR - include directory
    #  YAML_CPP_LIBRARIES    - libraries to link against
    
    # Compute paths
    get_filename_component(YAML_CPP_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
    set(YAML_CPP_INCLUDE_DIR "@[email protected]")
    
    # Our library dependencies (contains definitions for IMPORTED targets)
    include("${YAML_CPP_CMAKE_DIR}/yaml-cpp-targets.cmake")
    
    # These are IMPORTED targets created by yaml-cpp-targets.cmake
    set(YAML_CPP_LIBRARIES "@[email protected]")
    

    Indeed, grep-ing for CONFIG_INCLUDE_DIRS or EXPORT_TARGETS yields no results in the whole repository, so substitution should give an empty string.

    Am I missing something?

    Thanks!

    mattia

  • "Hide most of non-public..." PR breaks Windows build

    PR #984 broke the Windows use of the yaml-cpp branch. It was fixed when it was backed out on Sept 28th and it has broken the Windows usage again with the revert of the revert. Here is what happens with the broken submission:

    (ClCompile target) -> 
      D:\a\IIS-Module\IIS-Module\yaml-cpp\include\yaml-cpp\parser.h(13,10): fatal error C1083: Cannot open include file: 'yaml-cpp/dll.h': No such file or directory [D:\a\IIS-Module\IIS-Module\main\Native-IIS.vcxproj]
      D:\a\IIS-Module\IIS-Module\yaml-cpp\include\yaml-cpp\parser.h(13,10): fatal error C1083: Cannot open include file: 'yaml-cpp/dll.h': No such file or directory [D:\a\IIS-Module\IIS-Module\main\Native-IIS.vcxproj]
      D:\a\IIS-Module\IIS-Module\yaml-cpp\include\yaml-cpp\parser.h(13,10): fatal error C1083: Cannot open include file: 'yaml-cpp/dll.h': No such file or directory [D:\a\IIS-Module\IIS-Module\main\Native-IIS.vcxproj]
      D:\a\IIS-Module\IIS-Module\yaml-cpp\include\yaml-cpp\parser.h(13,10): fatal error C1083: Cannot open include file: 'yaml-cpp/dll.h': No such file or directory [D:\a\IIS-Module\IIS-Module\main\Native-IIS.vcxproj]
    
  • What's the point of yaml-cpp-targets?

    What's the point of yaml-cpp-targets?

    Currently I have yaml-cpp as a git submodule, that gets added using add_subdirectory to my own project. Calling find_package(yaml-cpp) on CMake 3.7 generates the following error:

    The file
    
       .../build/3rdparty/yaml-cpp/yaml-cpp-targets.cmake
    
      was generated by the export() command.  It may not be used as the argument
      to the include() command.  Use ALIAS targets instead to refer to targets by
      alternative names.
    

    After going through the yaml-cpp CMakeLists.txt I'm not quite sure why this file is needed to be generated. Generating this file through the export command generates the error shown above when being built inside another project (ie. as a submodule).
    Note that there's also a SO question here, that has an answer that is not ideal at all for my usage - I want to include it as a submodule and then build it.

    Is this really needed? Is there any way I can workaround this problem, besides simply disabling the generation of that file?

  • 0.5.0 tests do not compile

    0.5.0 tests do not compile

    What steps will reproduce the problem?
    1. compile run-tests
    
    What is the expected output? What do you see instead?
    compiled test
    
    
    What version of the product are you using? On what operating system?
    yaml-cpp 0.5.0, VS 2008, Win7
    
    Please provide any additional information below.
    The tests do not compile due to missing overloads for some template functions 
    for "const char[]" (which is for example called when accessing doc["somekey"] ).
    
    The attached patch fixes this. 
    
    

    Original issue reported on code.google.com by [email protected] on 10 Jan 2013 at 1:53

    Attachments:

  • CMAKE_INSTALL_PREFIX bug on Windows

    CMAKE_INSTALL_PREFIX bug on Windows

    The following line https://github.com/jbeder/yaml-cpp/blob/d0da14404ef7cc960ef01bbf97775ead08d3c477/CMakeLists.txt#L325-L330

    results in the following error:

    CMake Error at 3rdparty/yaml-cpp/CMakeLists.txt:325 (file):
      file RELATIVE_PATH must be passed a full path to the directory:
      install/CMake
    

    every time a cmake file in my project changes. I need to do a complete cache clean for it to be resolved (and then it happens again after I change something). This happens on Windows only and for 2 different projects that I'm aware of.

    One option would be to optionally disable yaml-cpp installation, or maybe provide an alternate code path if the path passed to that line is absolute.

  • [patch] fix for CMakeLists.txt to correctly support shared and static library with all targets

    [patch] fix for CMakeLists.txt to correctly support shared and static library with all targets

    Attached is a patch that will correct the CMakeLists.txt for trunk to...
    a) correctly create makefiles for shared and static libraries
    b) help users that use GCC before 3.4 to get rid of "-Wextra" a little bit 
    easier.
    
    I could build DLL and static library via CMake in VS2005 just fine.
    
    Kind regards
    Maddes
    
    P.S.:
    Yes, I still have to use GCC 3.2 for a project where we want to add YAML 
    support.
    
    

    Original issue reported on code.google.com by [email protected] on 3 Jan 2011 at 8:05

    Attachments:

  • Include cmake files in install

    Include cmake files in install

    This adds yaml-cpp-config.cmake, yaml-cpp-config-version.cmake, and yaml-cpp-targets.cmake to the cmake install. As a result, cmake's find_package can easily find yaml-cpp for software that depends on yaml-cpp.

    Closes jbeder/yaml-cpp#336 jbeder/yaml-cpp#127

  • Remove Boost dependency

    Remove Boost dependency

    Replaces usages of Boost template classes with equivalent C++11 STL classes. In the case of Boost::Iterator_Facade and Boost::Iterator_Adaptor, the STL has no direct equivalent so the functionality needed from the Boost classes was replicated as simply as possible.

    All tests are passing on GCC 4.9 and Clang 3.6, though I have not yet tested on MSVC.

  • YAML::convert<>::decode argument name rhs is confusing

    YAML::convert<>::decode argument name rhs is confusing

    In the tutorial, the example of YAML::convert<> defines a method static bool decode(const Node& node, Vec3& rhs) .

    From my understanding, the variable name rhs is commonly used for the right hand side of a binary operator during operator overloading (e.g. for operator/, operator=, operator== etc), which is often (typically unless rvalue ref in operator= (?)) a read-only input argument to the operator.

    While "rhs" is a valid variable name, using it for something which is the output of a method is (to me) somewhat confusing. I propose renaming it res or out in all instances of decode, in the tutorial and convert.h.

  • Iterating fails on Release build

    Iterating fails on Release build

    Setup

    File register_info.yaml:

    version: "1.0"
    organisations:
      - name: "company x"
        registers:
          - name: "register x"
            address: "0x20"
            bitmask: "0x12"
          - name: "register y"
            address: "0x21"
            bitmask: "0xFF"
    

    Code:

      const auto file = "register_info.yaml";
      try {
        const auto yaml = YAML::LoadFile(file);
        const auto& registers = yaml["organisations"][0]["registers"];
        if (registers.IsSequence()) {
          std::cout << "Parsed registers: \n";
          for (const auto& r : registers) {
            const auto ri = r.as<RegisterInfo>();
            std::cout << " - \"" << std::get<const char*>(ri.name) << "\"\n";
          }
        }
      } catch (YAML::Exception& e) {
        std::cerr << e.what() << "\n";
        return EXIT_FAILURE;
      }
    

    Issue

    when build with -DCMAKE_BUILD_TYPE=Debug prints:

    Parsed registers: 
     - "register x"
     - "register y"
    

    when build with -DCMAKE_BUILD_TYPE=Release prints:

    Parsed registers: 
     - ""
     - "register y"
    
  • Incompatibility with boost::nowide

    Incompatibility with boost::nowide

    yaml-cpp uses not standard-compliant parsing of a BOM, what makes it unusable with boost::nowide library. See the discussion in this issue.

    More concretely, the code in stream.cpp:200 uses multiple calls of std::ifstream::putback(), that is not guaranteed to work with all implementations according to the C++ standard.

  • CMake uninstall target

    CMake uninstall target

    The uninstall target in the project is always shown even if you don't have the install target. It should really be gated behind the ${YAML_CPP_INSTALL}. As a workaround in my projects I have been adding a dummy target before fetching yaml-cpp to prevent this:

    # Get rid of yaml uninstall target
    add_library(uninstall INTERFACE)
    
    set(YAML_CPP_BUILD_TESTS OFF CACHE BOOL "")
    set(YAML_CPP_BUILD_TOOLS OFF CACHE BOOL "")
    set(YAML_CPP_BUILD_CONTRIB OFF CACHE BOOL "")
    set(YAML_BUILD_SHARED_LIBS OFF CACHE BOOL "")
    set(YAML_CPP_INSTALL OFF CACHE BOOL "")
    set(YAML_CPP_FORMAT_SOURCE OFF CACHE BOOL "")
    FetchContent_Declare(
        yaml-cpp
        GIT_REPOSITORY      https://github.com/jbeder/yaml-cpp
        GIT_TAG             1b50109f7bea60bd382d8ea7befce3d2bd67da5f
    )
    
    FetchContent_MakeAvailable(yaml-cpp)
    
  • New formal release needed for MinGW64 users

    New formal release needed for MinGW64 users

    Package managers for both MSYS and VCPKG currently ship yaml-cpp version 0.7.0 based packages for MinGW64 because it is the latest formal release. Unfortunately this results in build errors due to issue #1026, which was fixed long after 0.7.0 released. Any chance of a new formal release so that people don't have to forego the benefit of package managers in order to use yaml-cpp in their MinGW64 projects? Thanks!

Header-only TOML config file parser and serializer for C++17 (and later!).
Header-only TOML config file parser and serializer for C++17 (and later!).

toml++ homepage ✨ This README is fine, but the toml++ homepage is better. ✨ Library features Header-only Supports the latest TOML release (v1.0.0), pl

Dec 4, 2022
A C++11 or library for parsing and serializing JSON to and from a DOM container in memory.
A C++11 or library for parsing and serializing JSON to and from a DOM container in memory.

Branch master develop Azure Docs Drone Matrix Fuzzing --- Appveyor codecov.io Boost.JSON Overview Boost.JSON is a portable C++ library which provides

Dec 1, 2022
libcluon is a small and efficient, single-file and header-only library written in modern C++ to power microservices.

libcluon Linux & OSX Build (TravisCI) Win64 Build (AppVeyor) Test Coverage Coverity Analysis CII Best Practices libcluon is a small single-file, heade

Nov 19, 2022
Nov 28, 2022
Cap'n Proto serialization/RPC system - core tools and C++ library
Cap'n Proto serialization/RPC system - core tools and C++ library

Cap'n Proto is an insanely fast data interchange format and capability-based RPC system. Think JSON, except binary. Or think Protocol Buffers, except

Dec 1, 2022
Header-only C++11 library to encode/decode base64, base64url, base32, base32hex and hex (a.k.a. base16) as specified in RFC 4648, plus Crockford's base32. MIT licensed with consistent, flexible API.

cppcodec Header-only C++11 library to encode/decode base64, base64url, base32, base32hex and hex (a.k.a. base16) as specified in RFC 4648, plus Crockf

Dec 5, 2022
Fast Binary Encoding is ultra fast and universal serialization solution for C++, C#, Go, Java, JavaScript, Kotlin, Python, Ruby, Swift

Fast Binary Encoding (FBE) Fast Binary Encoding allows to describe any domain models, business objects, complex data structures, client/server request

Dec 1, 2022
MessagePack implementation for C and C++ / msgpack.org[C/C++]

msgpack for C/C++ It's like JSON but smaller and faster. Overview MessagePack is an efficient binary serialization format, which lets you exchange dat

Nov 24, 2022
FlatBuffers Compiler and Library in C for C

OS-X & Ubuntu: Windows: The JSON parser may change the interface for parsing union vectors in a future release which requires code generation to match

Nov 26, 2022
Utility to convert any binary file into C source that can be compiled and linked to the executable.

bin2c Utility to convert any binary file into C source that can be compiled and linked to the executable. bin2o Utility to convert any binary file int

Jul 14, 2021
Experimental mutation testing tool for Swift and XCTest powered by mull
Experimental mutation testing tool for Swift and XCTest powered by mull

mull-xctest Experimental mutation testing tool for Swift and XCTest powered by mull. ⚠️ This tool is still experimental and under development. Install

Oct 29, 2022
Zmeya is a header-only C++11 binary serialization library designed for games and performance-critical applications

Zmeya Zmeya is a header-only C++11 binary serialization library designed for games and performance-critical applications. Zmeya is not even a serializ

Nov 2, 2022
Use to copy a file from an NTFS partitioned volume by reading the raw volume and parsing the NTFS structures.

ntfsDump Use to copy a file from an NTFS partitioned volume by reading the raw volume and parsing the NTFS structures. Similar to https://github.com/P

Nov 28, 2022
A C++11 ASN.1 BER Encoding and Decoding Library

fast_ber A performant ASN.1 BER encoding and decoding library written in C++11 Introduction fast_ber is a small, lightweight library for BER encoding

Dec 1, 2022
A high performance C++14 library for effortlessly reading and writing UBJSON

UbjsonCpp A high performance C++14 library for effortlessly reading and writing UBJSON This library implements UBJSON Draft 12 and Value semmantics Ab

Aug 2, 2022
High-performance specialized replacements for PHP's pack() and unpack() functions

ext-encoding High-performance specialized replacements for PHP's pack() and unpack() functions Under a profiler, it becomes obvious that PHP's pack()

Sep 17, 2022
Nov 29, 2021
International obfuscated contest: Small C program to minify HTML sources and generate a minified HTML output.
International obfuscated contest: Small C program to minify HTML sources and generate a minified HTML output.

HTML Minifier C International obfuscated contest: Just a small C program to minify HTML sources and generate a minified HTML output. Using $ gcc html-

Oct 27, 2022