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.
Scanned 5/30/2026
Install via CLI
openskills install ECNU-ICALK/AutoSkill---
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++
No comments yet. Be the first to comment!
Ultra-compressed communication mode. Cuts token usage ~75% by speaking like caveman while keeping full technical accuracy. Supports intensity levels: lite, full (default), ultra, wenyan-lite, wenyan-full, wenyan-ultra. Use when user says "caveman mode", "talk like caveman", "use caveman", "less tokens", "be brief", or invokes /caveman. Also auto-triggers when token efficiency is requested.
Adversarial multi-agent planning skill. Self-orchestrates 5 hostile category members (unspecified-low, unspecified-high, deep, ultrabrain, artistry) via team-mode for ruthless cross-critique debate, distills only the defensible insights, then MANDATORILY hands the distilled insight bundle to the `plan` agent for executable plan formalization. Use when planning needs maximum rigor and surfacing of weak assumptions, blind spots, and over-engineering. Triggers: 'hyperplan', 'hpp', '/hyperplan', ...
**Complete production-ready guide for Google Gemini embeddings API** This skill provides comprehensive coverage of the `gemini-embedding-001` model for generating text embeddings, including SDK usage, REST API patterns, batch processing, RAG integration with Cloudflare Vectorize, and advanced use cases like semantic search and document clustering. ---
Interview, source-challenge, verify, save, and ADR-gate fuzzy coding requests into Codex-ready implementation specs. Use when a feature, bugfix, refactor, migration, repo-wide change, or architecture task needs user-verified requirements, source-backed decisions, durable architecture decisions, acceptance criteria, validation commands, rollout notes, saved spec/ADR files, and a Codex execution prompt. Do not use when already fully specified or when the user wants direct implementation now.
Use when a repo needs CodeGraph plus ast-grep for Codex MCP setup, exploration, impact analysis, structural search, or safe refactor planning.