meojson

Guides JSON parsing, serialization, and struct jsonization with the meojson C++ library.

3.7k|317|Updated Mar 18, 2022
One-click install
npx skills add https://github.com/MaaEnd/MaaEnd --skill meojson
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: meojson
Source: https://github.com/MaaEnd/MaaEnd/tree/main/.agents/skills/meojson
Command: npx skills add https://github.com/MaaEnd/MaaEnd --skill meojson

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Writing JSON handling code in the MaaEnd cpp-algo module requires knowing the meojson library's specific API patterns, macro system, and error-handling conventions, and mistakes like silently swallowing parse failures or throwing on missing required fields cause subtle bugs.

Core Features & Use Cases

  • Safe Parsing Patterns: Provides recommended templates for parsing custom recognition parameters with proper optional checks, error logging, and early returns instead of exception-prone shortcuts.
  • Struct Jsonization: Documents the MEO_JSONIZATION macro family (MEO_OPT, MEO_KEY, MEO_TOJSON, MEO_FROMJSON) for bidirectional struct-to-JSON conversion with required and optional fields.
  • Custom Type Support: Explains ext::jsonization specializations for types like cv::Rect and cv::Point, plus enum reflection via MEOJSON_ENUM_RANGE.
  • Use Case: When implementing a new custom recognition algorithm in agent/cpp-algo that accepts JSON parameters, use this Skill to correctly parse the param string, deserialize it into a struct with optional fields, and write JSON detail output.

Quick Start

Ask the assistant to write a cpp-algo custom recognition param struct using meojson with safe parsing and MEO_JSONIZATION serialization.

Frequently Asked Questions about meojson

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I parse JSON safely with meojson in C++?

json::parse returns std::optional<json::value>, so always check the optional before use and log an error on failure. For struct deserialization, call from_json() and check its boolean return instead of using as<T>(), which throws on missing required fields.

How do I convert a C++ struct to JSON with MEO_JSONIZATION?

Add MEO_JSONIZATION(field1, field2, ...) inside the struct to generate to_json(), check_json(), and from_json() methods. Prefix fields with MEO_OPT to make them optional during deserialization, and use MEO_KEY("name") to override the JSON key name.

Does meojson support JSON with comments or BOM?

Yes, json::parsec parses JSONC strings with comments, and json::open(path, check_bom, with_comments) accepts flags for UTF-8 BOM checking and comment parsing. The default json::open(path) is strict JSON with neither enabled.

How do I add JSON support for custom types like cv::Rect?

Specialize json::ext::jsonization<T> in the json::ext namespace with to_json, check_json, and from_json methods. MaaUtils already provides specializations for cv::Point, cv::Rect, cv::Size, std::filesystem::path, and std::chrono::milliseconds.

Why does meojson as<T>() throw an exception?

as<T>() throws when the JSON type mismatches or a required field is missing during struct conversion. Use find<T>() for optional lookups, is<T>() for type checks, or from_json() with return-value validation for structs.