I’m trying to parse .json in C++ using nlohmann/json library but it’s failing during compilation

I’m trying to parse .json in C++ using nlohmann/json library on Ubuntu but during compilation it fails every time and I can’t understand why it’s happening like this, help!

yt_dlp_cpp.hpp

#pragma once

#ifndef YT_DLP_CPP_HPP
#define YT_DLP_CPP_HPP

#include <string>
#include <vector>

namespace yt_dlp_cpp
{
    struct format_info
    {
        std::string format_id, format_note, ext;
        size_t width, height;
    };

    class yt_dlp
    {
      public:
        yt_dlp();

        yt_dlp(const std::string &url);

        void set_url(const std::string &url);

        const std::vector<format_info> get_formats() const;

      private:
        struct info
        {
            std::string url;
        } info;

        std::vector<format_info> formats;
    };
} // namespace yt_dlp_cpp

#endif // YT_DLP_CPP_HPP

yt_dlp_cpp.cpp

#include <boost/process.hpp>
#include <memory>

#include "nlohmann/json.hpp"
#include "yt_dlp_cpp.hpp"

std::unique_ptr<nlohmann::json> yt_dlp_json_info;

inline void yt_dlp_parse_json_info(const std::string &url)
{
    boost::process::ipstream pipe_stream;
    boost::process::child c(
        "yt-dlp --no-playlist --skip-download --dump-json " + url,
        boost::process::std_out > pipe_stream
    );

    std::string temp_line, output;

    while (std::getline(pipe_stream, temp_line)) output += temp_line;

    c.wait();

    yt_dlp_json_info =
        std::make_unique<nlohmann::json>(nlohmann::json::parse(output));
}

inline void yt_dlp_init_formats(std::vector<yt_dlp_cpp::format_info> &formats)
{
    for (const auto &i : yt_dlp_json_info->at("formats"))
    {
        formats.push_back(
            {i["format_id"], i["format_note"], i["ext"],
             i["width"].get<size_t>(), i["height"].get<size_t>()}
        );
    }
}

yt_dlp_cpp::yt_dlp::yt_dlp() {}

yt_dlp_cpp::yt_dlp::yt_dlp(const std::string &url) { set_url(url); }

void yt_dlp_cpp::yt_dlp::set_url(const std::string &url)
{
    yt_dlp_parse_json_info(url);
    yt_dlp_init_formats(formats);
    info.url = url;
}

const std::vector<yt_dlp_cpp::format_info>
    yt_dlp_cpp::yt_dlp::get_formats() const
{
    return formats;
}

main.cpp

#include <iostream>

#include "yt_dlp_cpp.hpp"

using namespace std;

int main()
{
    yt_dlp_cpp::yt_dlp yt_dlp("https://youtu.be/Sab6wfnmTcY?si=wE-kXRdHtlNLxVE0"
    );

    for (const auto &i : yt_dlp.get_formats()) cout << i.ext << endl;

    return EXIT_SUCCESS;
}

So I compiled this code using xmake and every time I’m getting compilation error…

Compilation error

main: nlohmann/json.hpp:21450: const value_type& nlohmann::json_abi_v3_11_3::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>::operator[](const typename nlohmann::json_abi_v3_11_3::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>::object_t::key_type&) const [with ObjectType = std::map; ArrayType = std::vector; StringType = std::__cxx11::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatType = double; AllocatorType = std::allocator; JSONSerializer = nlohmann::json_abi_v3_11_3::adl_serializer; BinaryType = std::vector<unsigned char>; CustomBaseClass = void; nlohmann::json_abi_v3_11_3::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>::const_reference = const nlohmann::json_abi_v3_11_3::basic_json<>&; typename nlohmann::json_abi_v3_11_3::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>::object_t::key_type = std::__cxx11::basic_string<char>; nlohmann::json_abi_v3_11_3::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>::object_t = std::map<std::__cxx11::basic_string<char>, nlohmann::json_abi_v3_11_3::basic_json<>, std::less<void>, std::allocator<std::pair<const std::__cxx11::basic_string<char>, nlohmann::json_abi_v3_11_3::basic_json<> > > >]: Assertion `it != m_data.m_value.object->end()' failed.
error: execv(/home/sasha/yt_dlp_cpp/build/linux/x86_64/debug/main ) failed(-1)

New contributor

Александр Алибеков is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật