as-json

Extracts JSON from mixed text, code fences, and optionally retrieves specific fields recursively.

10|Updated Jul 22, 2025
One-click install
npx skills add https://github.com/bdambrosio/Cognitive_workbench --skill as-json
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: as-json
Source: https://github.com/bdambrosio/Cognitive_workbench/tree/main/src/tools_out/as-json
Command: npx skills add https://github.com/bdambrosio/Cognitive_workbench --skill as-json

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill cleans up messy text, extracting structured JSON data even when it's embedded within other content like explanations or code fences.

Core Features & Use Cases

  • JSON Extraction: Reliably pulls JSON objects from LLM responses or other text.
  • Noise Removal: Automatically strips preambles, postambles, and markdown code fences (json ... ).
  • Field Extraction: Optionally extracts specific field values from the JSON, recursively searching nested structures.
  • Use Case: You receive an LLM response that includes a JSON payload along with explanatory text. Use this Skill to isolate and extract just the JSON, or a specific piece of data like a URL or an email address from within it.

Quick Start

Use the as-json skill to extract the JSON from the variable $llm_response and save it to $parsed.

Frequently Asked Questions about as-json

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

FAQPage Schema
How do I extract JSON from an LLM response that includes extra text and code fences?

To extract JSON from an LLM response, this Skill parses mixed-content inputs by automatically stripping explanatory preambles, postambles, and markdown code fences to isolate the valid JSON payload.

Can I pull a specific field from nested JSON embedded inside messy text?

Yes, you can extract specific field values from nested JSON by enabling recursive field extraction, which searches through the identified JSON structure to return the targeted data point.

What is the best way to clean up messy text and isolate a structured JSON payload?

The best way to clean up messy text and isolate a JSON payload is to use a parsing tool that validates JSON integrity while automatically removing surrounding non-JSON content and formatting noise.

Does this JSON extraction approach handle mixed-content inputs with embedded code blocks?

Yes, this JSON extraction approach handles mixed-content inputs by identifying and extracting structured data even when it is embedded within text or formatted inside markdown code blocks.

Why does my JSON parsing fail when LLM output contains explanatory preambles?

JSON parsing fails when LLM output contains preambles because standard validators expect pure structures, but this Skill resolves the issue by stripping the noise and validating the extracted JSON integrity.

How do I validate JSON integrity after extracting it from mixed text sources?

To validate JSON integrity after extraction from mixed text, this Skill automatically checks the isolated payload structure and provides either a structured output or specific requested field values.