Skip to main content
Coding

JSON Prompt Templates for Structured Coding Tasks

Explore JSON prompt examples for coding tasks. See how to define inputs, requirements and output structure, then customize a template for your project.

Use JSON to make the coding brief explicit

A structured coding brief separates the requested behavior, input type, edge cases and examples. It gives you something concrete to compare against the resulting code.

Example: normalize a list of tags

{
  "task": "Implement normalizeTags(tags) in JavaScript",
  "input": "An array of strings",
  "requirements": [
    "Trim whitespace and convert tags to lowercase",
    "Discard empty tags",
    "Remove duplicates while preserving first occurrence order",
    "Throw TypeError for a non-array input or any non-string element"
  ],
  "examples": [
    {"input": [" SEO ", "seo", "Writing", ""], "expected": ["seo", "writing"]},
    {"input": [], "expected": []}
  ],
  "output": "Function implementation and tests"
}

An implementation matching this brief

function normalizeTags(tags) {
  if (!Array.isArray(tags) || tags.some(tag => typeof tag !== "string")) {
    throw new TypeError("Expected an array of strings");
  }
  return [...new Set(tags.map(tag => tag.trim().toLowerCase()).filter(Boolean))];
}

Check the behavior independently

For this example, check an empty array, whitespace-only strings, repeated tags, first-occurrence order, a non-array input and an array containing a number. The invalid-input cases should throw rather than silently convert values.

The example defines lowercase matching without locale-specific rules. If your application needs a particular language, Unicode normalization or case-sensitive tags, make that requirement explicit and add examples that expose the difference.

Use the brief during review

  1. Check that the function’s name and interface match the request.
  2. Run cases derived from the intended behavior, including invalid inputs.
  3. Review dependencies and any unexpected side effects.
  4. Explain failures precisely before requesting a repair.
  5. Run the relevant checks again after changing the implementation.

Structured instructions make requirements easier to inspect. They do not establish that generated code is correct or secure; your review and tests supply that evidence.

Browse JSON coding prompts and the Build-Test-Repair Code Loop for related starting points.

Free · The Weekly Prompt

Get Better AI Prompts Every Week

Useful prompts, practical AI tips, and selected tools and opportunities.