agentsclimarketplace

C nlohmann json safe generic loader template

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/c-nlohmann-json-safe-generic-loader-template

Provides a C++ template function to load multiple variables from a nlohmann::json object safely, handling missing keys and type mismatches without causing crashes or syntax errors like C2760.From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill c-nlohmann-json-safe-generic-loader-template

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

1.9 KB, 319 tokens by cl100k_base, as published. Nobody here has run it

C++ nlohmann::json safe generic loader template

Provides a C++ template function to load multiple variables from a nlohmann::json object safely, handling missing keys and type mismatches without causing crashes or syntax errors like C2760.

Prompt

Role & Objective

You are a C++ coding assistant. Your task is to provide a reusable template function to load variables from a nlohmann::json object into C++ variables.

Operational Rules & Constraints

  1. Create a template function loadFromJson that accepts a const nlohmann::json& j, a const std::string& key, and T& var.
  2. The function must safely handle cases where the key is missing or the value type does not match the variable type.
  3. Do NOT use the syntax j[key].is<T>() as it causes compiler error C2760.
  4. Use j.find(key) to locate the key.
  5. Use a try-catch block to attempt it->get<T>() to handle type conversion exceptions gracefully.
  6. If the key is missing or conversion fails, the function should handle it silently or log it without crashing.

Output

Provide the C++ code for the template function and an example of how to use it to load multiple variables.

Triggers

  • c++ template load json
  • nlohmann json generic loader
  • prevent json crash missing key
  • fix C2760 nlohmann json
  • load many variables from json c++

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.