Show HN: Structured JSON Prompts for AI Image Generation

4 months ago 21

image-json-gen is a lightweight repository for defining and serializing structured image-generation prompts in TypeScript. Using a well-defined JSON schema and SuperJSON, it ensures consistent, reproducible prompts for AI-driven image generation tools.

  • Type-safe Prompt Interface: Defines a comprehensive ImageGenerationPrompt interface covering scene, subjects, style, lighting, composition, camera settings, resolution, and more.
  • JSON Schema Integration: Adheres to a published JSON schema (image-generation.schema.json), enabling validation and tooling support.
  • SuperJSON Serialization: Uses SuperJSON to preserve advanced types and metadata when writing prompts to disk.
  • One-step Prompt Export: Simple script to serialize your prompt and output a prompt.json file ready for consumption by AI studios or pipelines.
  • Bun
git clone https://github.com/your-org/image-json-gen.git cd image-json-gen bun install
  1. **Edit **src/index.ts

    • Update the prompt object to reflect your desired scene and settings.
    • Adjust fields like scene, subjects, style, lighting, resolution, etc.
  2. **Generate **prompt.json

    bun run src/index.ts # or `npm run start` if configured

    This writes prompt.json in the project root, formatted and serialized via SuperJSON.

  3. Consume the Prompt

    Import or load prompt.json in your AI pipeline or tool:

    import prompt from "./prompt.json"; // Send `prompt` to your image-generation service

The JSON output conforms to image-generation.schema.json.

{ "$schema": "https://.../image-generation.schema.json", "scene": "...", "subjects": [...], // ... other prompt fields }
  • Model Identifier: Specify model_identifier to target different AI backends.
  • Seeds & Guidance: Control reproducibility with seed, guidance_scale, and num_inference_steps.
  • Negative Prompts: Use negative_prompt to exclude unwanted artifacts.

MIT © xcaeser

Read Entire Article