← 返回
未分类

Json To Api

Use when (1) user provides JSON data and asks to design a REST API endpoint around it. (2) user says "create an API for this", "design an endpoint", "write t...
用于以下场景:(1) 用户提供 JSON 数据并要求为其设计 REST API 端点;(2) 用户说“为此创建 API”“设计端点”“编写 API 代码”等。
wangjipeng977
未分类 clawhub v1.0.1 1 版本 100000 Key: 无需
★ 1
Stars
📥 344
下载
💾 0
安装
1
版本
#latest

概述

JSON to API

Use when (1) user provides JSON data and asks to design a REST API endpoint around it. (2) user says "create an API for this", "design an endpoint", "write the OpenAPI spec for this JSON", or "make this a web API". (3) user pastes a JSON payload and wants the corresponding request/response schema.

Core Position

This skill solves the specific problem of: raw JSON data needs a proper API contract — endpoints, HTTP methods, status codes, and schemas — not just a data dump.

This skill IS NOT:

  • A data transformation tool — it designs the interface, not the implementation
  • A backend code generator — it produces specs, not runnable server code
  • An API client — it designs the server-side contract

This skill IS activated ONLY when: JSON data + API design intent are both present.

Modes

/json-to-api

Default mode. Designs REST API endpoints from JSON data with full OpenAPI 3.0 spec.

When to use: User provides JSON and wants endpoint design, HTTP methods, and request/response schemas.

/json-to-api/expand

Adds pagination, filtering, sorting, and embedded resource support to the base design.

When to use: The JSON represents a collection and user wants a production-grade API surface.

Execution Steps

Step 1 — Analyze the JSON Structure

  1. Receive JSON (pasted, file, or path)
  2. Detect data type:
    • Single object: likely a resource with GET (one), PUT/PATCH (update), DELETE
    • Array of objects: likely a collection with GET (list), POST (create)
    • Nested object: indicates sub-resources or embedded entities
    • Flat key-value: simple configuration or state object
  3. Identify resource candidates:
    • Top-level keys become resource names
    • Nested objects become sub-resources
    • Arrays become collection endpoints
  4. Infer data types for each field: string, number, boolean, null, array, object

Step 2 — Design API Surface

Determine resources and endpoints:

JSON ShapeHTTP MethodEndpoint
---------
Single objectGETGET /{resource}/{id}
Array of objectsGET (list), POST (create)GET /{resource}, POST /{resource}
Nested resourceGETGET /{resource}/{id}/{sub-resource}
Object with ID fieldPUT, PATCH, DELETEPUT /{resource}/{id}

Step 3 — Write OpenAPI 3.0 Schema

Generate the full OpenAPI spec:

openapi: 3.0.0
info:
  title: Resource API
  version: 1.0.0
paths:
  /resources:
    get:
      summary: List all resources
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/Resource'

For each schema field:

  • Map JSON types to OpenAPI types
  • Mark required fields (non-nullable, must be present)
  • Add example values from the provided JSON

Step 4 — Validate

  • All JSON fields are represented in the schema
  • HTTP methods are appropriate for the resource type
  • Status codes are standard (200, 201, 400, 404, 500)
  • No invented endpoints not implied by the JSON structure

Mandatory Rules

Do not

  • Do not invent API endpoints not implied by the JSON structure
  • Do not set arbitrary status codes (use standard REST conventions)
  • Do not add authentication schemes not mentioned by the user
  • Do not assume database schema — design the API surface only

Do

  • Use plural nouns for collection endpoints (/users, not /user)
  • Map JSON field names to camelCase in the schema
  • Include the provided JSON as an example in the schema
  • Follow REST conventions: GET (no body), POST/PUT/PATCH (JSON body), DELETE (no body)

Quality Bar

A good output:

  • Every field in the JSON appears in the schema with correct type
  • HTTP methods and endpoints match JSON structure
  • OpenAPI spec is valid YAML and renderable in Swagger UI
  • Examples in schema match the provided JSON values

A bad output:

  • Missing fields from the original JSON
  • Wrong HTTP method for the operation (GET with body)
  • Non-standard status codes (201 for GET, 200 for DELETE)
  • camelCase/snake_case inconsistency in field naming

Good vs. Bad Examples

ScenarioBad OutputGood Output
---------
Array of usersGET /user (singular)GET /users (plural)
Nested address objectFlattened into user objectGET /users/{id}/addresses as sub-resource
Optional phone fieldMarked as requiredMarked optional with nullable: true
Created timestampNumber typeString with format: date-time

References

  • references/ — OpenAPI 3.0 schema templates, HTTP method conventions, status code guide

版本历史

共 1 个版本

  • v1.0.1 当前
    2026-05-21 14:05 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

Csv To Chart

wangjipeng977
用于以下情况:(1) 用户粘贴或上传 CSV 数据并要求生成图表或可视化;(2) 用户想要“绘制”或“可视化”表格数据;(3)…
★ 1 📥 414

Sql To Dashboard

wangjipeng977
用于以下情况:(1) 用户提供SQL查询并要求根据结果生成图表、仪表板或数据可视化;(2) 用户说“把这个显示为图表”等类似请求。
★ 1 📥 388

Text To Sql

wangjipeng977
用于以下场景:①用户用自然语言描述所需数据并请求对应的SQL查询;②用户说“write SQL for this”或“convertto query”等。
★ 1 📥 1,274