Json Result Formatting logo

Json Result Formatting

Organization
cxcscmu
json-result-formatting

Format query results to JSON with proper structure and token tracking

Overview

Publishercxcscmu
RepositorySkillLearnBench
Skill namejson-result-formatting
Stars
91
Forks
7
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by cxcscmu on GitHub. Read the source before you install it.

Installation

Install the Json Result Formatting AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/cxcscmu/SkillLearnBench/tree/main/skills/b1-one-shot-claude-haiku-4-5/enterprise-information-search/json-result-formatting
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/cxcscmu/SkillLearnBench.git /tmp/SkillLearnBench
mkdir -p .claude/skills
cp -r /tmp/SkillLearnBench/skills/b1-one-shot-claude-haiku-4-5/enterprise-information-search/json-result-formatting .claude/skills/json-result-formatting
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Json Result Formatting in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Json Result Formatting on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Json Result Formatting is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

JSON Result Formatting

Overview

Formatting retrieved data into standardized JSON output with answer lists and token tracking.

Use Cases

  • Writing query results to JSON files
  • Formatting answers as lists regardless of count
  • Tracking API token consumption
  • Creating consistent output files for downstream processing

Required Output Format

json
{
    "q1": {"answer": ["xxx"], "tokens": 123},
    "q2": {"answer": ["xxx", "yyy"], "tokens": 456},
    "q3": {"answer": [], "tokens": 789}
}

Code Examples

Initialize Result Container

python
import json

result = {
    "q1": {"answer": [], "tokens": 0},
    "q2": {"answer": [], "tokens": 0},
    "q3": {"answer": [], "tokens": 0}
}

Add Single Answer

python
def add_answer(result, question_key, answer_items, tokens=0):
    """Add answer as list (always list format)"""
    # Ensure answer_items is a list
    if isinstance(answer_items, str):
        answer_items = [answer_items]
    elif not isinstance(answer_items, list):
        answer_items = list(answer_items)

    result[question_key] = {
        "answer": answer_items,
        "tokens": int(tokens)
    }
    return result

# Usage
result = add_answer(result, "q1", ["eid_1e9356f5"], tokens=150)
result = add_answer(result, "q2", employee_ids_list, tokens=200)

Write to JSON File

python
import json

def write_result_file(result, filepath):
    """Write result to JSON file"""
    with open(filepath, 'w') as f:
        json.dump(result, f, indent=4)
    print(f"Results written to {filepath}")

# Usage
write_result_file(result, '/root/answer.json')

Track Token Usage (Without API)

python
import json

# For local data processing, estimate tokens
def estimate_tokens_from_text(text):
    """Rough estimation: ~4 characters per token"""
    return len(text) // 4

# Better: track actual API usage
def track_tokens(usage_dict):
    """Track from API response"""
    if hasattr(usage_dict, 'input_tokens'):
        return usage_dict.input_tokens + usage_dict.output_tokens
    return 0

Complete Result Building Flow

python
import json

# Initialize
result = {
    "q1": {"answer": [], "tokens": 0},
    "q2": {"answer": [], "tokens": 0},
    "q3": {"answer": [], "tokens": 0}
}

# Q1: Authors and reviewers
authors = ["eid_1e9356f5"]
reviewers = ["eid_06cddbb3", "eid_99835861"]
result["q1"]["answer"] = authors + reviewers
result["q1"]["tokens"] = 150  # Estimated or tracked

# Q2: Competitor insights team members
competitor_team = ["eid_xxx", "eid_yyy"]
result["q2"]["answer"] = competitor_team
result["q2"]["tokens"] = 200

# Q3: Demo URLs
urls = ["https://example.com/demo1", "https://example.com/demo2"]
result["q3"]["answer"] = urls
result["q3"]["tokens"] = 100

# Write output
with open('/root/answer.json', 'w') as f:
    json.dump(result, f, indent=4)

Best Practices

  1. Always Use Lists

    • Single item: ["value"] not "value"
    • Multiple items: ["item1", "item2"]
    • Empty: [] not null
  2. Token Tracking

    • For Claude API: Use response.usage.input_tokens + response.usage.output_tokens
    • For local processing: Track API calls made and sum their tokens
    • If no API: Use 0 or estimate conservatively
  3. Data Validation

    python
    # Ensure no duplicates
    result["q1"]["answer"] = list(set(result["q1"]["answer"]))
    
    # Ensure proper types
    result["q2"]["tokens"] = int(result["q2"]["tokens"])
  4. Indent and Format

    python
    # Always use proper formatting
    json.dump(data, f, indent=4)

Validation Checklist

  • All question keys present (q1, q2, q3)
  • All answers are lists
  • All token counts are integers
  • No null values (use empty list [] instead)
  • Output file is valid JSON
  • Can be loaded with json.load()

Testing Output

python
import json

# Verify output file
with open('/root/answer.json', 'r') as f:
    data = json.load(f)

# Check structure
for q_key, q_data in data.items():
    assert "answer" in q_data
    assert "tokens" in q_data
    assert isinstance(q_data["answer"], list)
    assert isinstance(q_data["tokens"], int)
    print(f"{q_key}: {len(q_data['answer'])} items, {q_data['tokens']} tokens")

Frequently asked questions

What does the Json Result Formatting AI skill do?

Format query results to JSON with proper structure and token tracking

Why use Json Result Formatting on TypingMind?

Because you install it once and use it with any model. Json Result Formatting is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Json Result Formatting in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/cxcscmu/SkillLearnBench/tree/main/skills/b1-one-shot-claude-haiku-4-5/enterprise-information-search/json-result-formatting. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Json Result Formatting?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Json Result Formatting?

As many as you like. As long as a model supports skills, you can use Json Result Formatting with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Json Result Formatting AI skill free?

Yes. It is published on GitHub by cxcscmu under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇