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:

Issues
  • 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 "@[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

    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
  • 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
  • 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.

    opened by matteblair 14
  • Basic update to CMakeLists.txt to address #1116

    Basic update to CMakeLists.txt to address #1116

    Changes are as per https://github.com/jbeder/yaml-cpp/issues/1116#issuecomment-1166975890

    I also updated CONTRIBUTING.md as it took me a moment to find the correct test script (it is no longer called 'run_tests') - might help someone else.

    opened by stephematician 1
  • Using static library Windows

    Using static library Windows

    yaml-cpp 0.7.0 broke one of my projects (which was using 0.6.3) at least on Windows as it seems that the installed cmake config (at least with cmake v3.23.1) doesn't set "YAML_CPP_STATIC_DEFINE" by default ... even though the default build/install is a static library.

    The result is that when I build my project I see a message "Defining YAML_CPP_API for DLL import" then an ensuing barrage of linker errors (as well as CN4251 warnings).

    Is this expected behaviour? Is it up to projects which import the yaml-cpp (target) to explicitly specify that the static library defines should be used via the macro?

    Related: #1078

    opened by stephematician 1
  • No way to modify a single `Node` to emit with `SingleQuoted`?

    No way to modify a single `Node` to emit with `SingleQuoted`?

    I've been beating my head into the wall to get this library to allow me to set a single YAML::Value to YAML::SingleQuoted. This is a pretty straightforward problem that I think most people can guess at: I'm editing a docker-compose.yml file and I'm losing every quote literal.

    I know I can use YAML::Emitter and << into it with YAML::SingleQuoted to emit the entire document, but keys and values single quoted, but that isn't what I need. I realize quotes aren't the standard here in YAML format. But is there any way to read and preserve them?

    opened by mathemaphysics 0
  • Export library directory and shared libs to CMake config

    Export library directory and shared libs to CMake config

    This pull request adds two new exported variables to the CMake config:

    YAML_CPP_LIBRARY_DIR - points to the directory containing the built library files YAML_CPP_SHARED_LIBS_BUILT - boolean value, lets users know whether shared libraries were built or not

    I am trying to embed yaml-cpp into a project. I need YAML_CPP_LIBRARY_DIR so I can let CMake know where the libraries to link to are, and I need YAML_CPP_SHARED_LIBS_BUILT to know if I can link to the shared libraries or not.

    opened by darktohka 0
  • Could you provide a method to dynamic access like this node(

    Could you provide a method to dynamic access like this node("a","b","c",...)

    As a user, sometimes we do not know how deep the yaml file will be. So it would be better if we can access the data like this YAML::Node node = YAML::LoadFile(file_path); T x = node("a","b","c",...).as();

    opened by littlebr369 8
  • RegEx::MatchUnchecked(const Source& source) exception

    RegEx::MatchUnchecked(const Source& source) exception

    Hello everyone! Sometimes when i use << YAML::BeginMap it leads to crash. image image

    It would really be a problem if it happened every time, but it happens in about 3%, and it seems to me that this is a problem in the library and not in my code because all I do is write to the Emitter BeginMap.

    opened by KennyProgrammer 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 805 Jun 21, 2022
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 294 Jun 20, 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 79 Apr 23, 2022
Microsoft 2.4k Jun 27, 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 9k Jun 23, 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

Topology 458 Jun 23, 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 567 Jun 16, 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

MessagePack 2.5k Jun 27, 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 503 Jun 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 Mar 3, 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 95 Jun 22, 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 40 Jun 18, 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 69 May 22, 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 Nov 10, 2021
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 13 Apr 9, 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 9 May 28, 2022