Skip to content
Back to skills

C Nlohmann Json Safe Generic Loader Template

ASecurity

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.

  • 611 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added May 30, 2026
ai-agentsc++

Security analysis

A100/100

Scanned May 30, 2026

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

Installs into .claude/skills of the current project.

Are you the author of C Nlohmann Json Safe Generic Loader Template?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for C Nlohmann Json Safe Generic Loader Template
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-c-nlohmann-json-safe-generic-loader-template/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-c-nlohmann-json-safe-generic-loader-template)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "b81f2ab2-84ee-4d1e-83a9-199ba2b3fda4"
name: "C++ nlohmann::json safe generic loader template"
description: "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."
version: "0.1.0"
tags:
  - "c++"
  - "nlohmann-json"
  - "template"
  - "error-handling"
  - "generic-programming"
triggers:
  - "c++ template load json"
  - "nlohmann json generic loader"
  - "prevent json crash missing key"
  - "fix C2760 nlohmann json"
  - "load many variables from json c++"
---

# 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++

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.