A YAML parser and emitter in C++

Overview

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.

    opened by Ortham 36
  • 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

    enhancement 
    opened by GoogleCodeExporter 35
  • 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

    Priority-Medium Type-Defect auto-migrated 
    opened by GoogleCodeExporter 22
  • 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 "@CONFIG_INCLUDE_DIRS@")
    
    # 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 "@EXPORT_TARGETS@")
    

    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

    opened by mattia- 21
  • "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]
    
    opened by noelotterness 19
  • 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?

    opened by tambry 18
  • 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:

    Priority-Medium Type-Defect auto-migrated 
    opened by GoogleCodeExporter 18
  • msvc: enable CMP0091 to use MSVC_RUNTIME_LIBRARY

    msvc: enable CMP0091 to use MSVC_RUNTIME_LIBRARY

    Per https://cmake.org/cmake/help/latest/policy/CMP0091.html, we need to enable policy CMP0091 if we want to make use of MSVC_RUNTIME_LIBRARY and/or CMAKE_MSVC_RUNTIME_LIBRARY. Fixes issue #912.

    opened by tomlogic 17
  • 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.

    opened by VelocityRa 15
  • [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:

    Priority-Medium Type-Defect auto-migrated 
    opened by GoogleCodeExporter 15
  • 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

    opened by paulnovo 14
  • What could possibly cause such a mistake?

    What could possibly cause such a mistake?

    Undefined symbols for architecture x86_64:
      "YAML::detail::node_data::empty_scalar", referenced from:
          YAML::Node::Scalar() const in config.cc.o
      "YAML::operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, YAML::Node const&)", referenced from:
          jujimeizuo::Config::LoadFromYaml(YAML::Node const&) in config.cc.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make[2]: *** [../lib/libsrc.dylib] Error 1
    make[1]: *** [CMakeFiles/src.dir/all] Error 2
    make: *** [all] Error 2
    

    when I define std::list<std::pair<std::string, const YAML::Node> >& output, and execute the follow:

    output.push_back(std::make_pair(prefix, node));
    

    then the program compile failure, and I get some mistakes as above. But when I Comment out that, I can make successfully.

    opened by jujimeizuo 0
  • Loading of block sequence with tag fails

    Loading of block sequence with tag fails

    Loading of block sequence with tag (standard or application) and less than 3 spaces (at the line begin) fails with exception: "end of sequence not found". Such YAML is declared valid with number of online validators.

    More details and examples

    All following examples are successfully loaded

    1. not block sequence
    key: !t |
     multiple
     words
    
    1. no tag
    key: 
    - |
     multiple
     words
    
    1. more than 2 spaces (3)
    key: 
    - !!str |
       multiple
       words
    

    but the following fail (1 or 2 spaces before "multiple" and "words"):

    1. application tag
    key: 
    - !t |
     multiple
     words
    
    1. standard tag
    key: 
    - !!str |
      multiple
      words
    

    Possible solution

    The change in Scanner::ScanTag:

    • remove InsertPotentialSimpleKey(); call

    seems to solve this problem, but breaks some of existing tests.

    opened by ncaklovic 0
  • 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.

    opened by klenze 0
  • 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"
    
    opened by Osteri 2
  • 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.

    opened by H5117 0
Releases(yaml-cpp-0.7.0)
  • yaml-cpp-0.7.0(Jul 10, 2021)

  • yaml-cpp-0.6.3(Sep 25, 2019)

    Patch release on 0.6.0:

    • bug fixes
    • CMake updates, now requiring 3.1

    0.6.0 release notes:

    • requires C++11
    • removes dependency on Boost
    • bug fixes
    • performance improvements
    Source code(tar.gz)
    Source code(zip)
  • yaml-cpp-0.6.2(Mar 6, 2018)

    Patch release on 0.6.0, fixing installation bug and mismatched versioning.

    0.6.0 release notes:

    requires C++11 removes dependency on Boost bug fixes performance improvements

    Source code(tar.gz)
    Source code(zip)
  • yaml-cpp-0.6.1(Feb 2, 2018)

    WARNING: This release's CMake version doesn't match its tag. Please use 0.6.2 instead.

    Patch release on 0.6.0, fixing installation bug.

    0.6.0 release notes:

    • requires C++11
    • removes dependency on Boost
    • bug fixes
    • performance improvements
    Source code(tar.gz)
    Source code(zip)
  • yaml-cpp-0.6.0(Jan 28, 2018)

  • yaml-cpp-0.5.3(Jan 10, 2016)

Owner
Jesse Beder
Jesse Beder
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

Mark Gillard 970 Jan 9, 2023
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

Boost.org 333 Dec 29, 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

Christian Berger 81 Nov 30, 2022
Microsoft 2.5k Dec 31, 2022
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

Cap'n Proto 9.5k Jan 1, 2023
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

Topology 491 Dec 28, 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

Ivan Shynkarenka 654 Jan 2, 2023
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

MessagePack 2.6k Dec 31, 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

null 550 Dec 25, 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

Vadim A. Anisimov 16 Jul 14, 2021
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

Yuta Saito 43 Dec 14, 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

Sergey Makeev 99 Dec 24, 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

null 102 Dec 30, 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

null 73 Dec 21, 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

Ibrahim Timothy Onogu 21 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()

PMMP 15 Sep 17, 2022
Telepati 2 Nov 29, 2021
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-

Max Base 10 Oct 27, 2022