← All examples

JSON: what works

Minu is an HTML-fragment loader. JSON is supported for attribute configuration, not as a request body or response format. This page shows both sides clearly.

1. JSON in attributes (works)

minu-vals and minu-headers are JSON objects. Minu parses them before the request; nested values are stringified into form fields.

The echoed values appear here.

2. Raw JSON response (not parsed)

A response with Content-Type: application/json is still treated as text. Minu swaps the raw JSON string into the target; it does not render fields.

Raw body appears here.

3. Custom fetch + JSON renderer (workaround)

When the endpoint is JSON-only, use native fetch and render the HTML yourself. Minu is not involved in this request.

Parsed items appear here.

Support matrix

ThingSupported?Notes
minu-vals JSON object✅Merged into request values.
minu-headers JSON object✅Merged into request headers.
JSON request body❌Bodies are form-urlencoded or multipart.
JSON response rendering❌Responses are HTML fragments.
Server-side JSON → HTML✅Render the fragment, then let Minu swap it.
Client-side fetch() + JSON✅Use your own renderer; bypass Minu.

Why responses must be HTML

  1. Minu calls response.text(); there is no JSON parser in the runtime.
  2. The text goes through the sanitizer and then into a swap target.
  3. That is the whole contract: HTML in, HTML out. It keeps the library small and predictable.
  4. For a JSON API, render HTML on the server (or use fetch and your own renderer).
// works: JSON config in attributes
<button minu-post="/save"
        minu-vals='{"source":"demo","nested":{"level":2}}'
        minu-headers='{"X-Demo-Token":"abc"}'>
    Save
</button>

// does not work: JSON body / JSON response
// Minu sends form fields and expects an HTML fragment.

If Minu needs to consume a JSON API directly, add a server-side adapter or ask for a separate JSON mode — it is intentionally not part of the core build.