Skip to content

Conversation

@scriptogre
Copy link

Introduces htmx.parseJSON() method with optional relaxed syntax that accepts unquoted object keys and auto-wraps bare properties in braces, making inline attribute configurations significantly more readable.

Features:

  • Unquoted keys: {timeout: 5000} instead of {"timeout": 5000}
  • Auto-wrapping: timeout: 5000 instead of {timeout: 5000}
  • Works in hx-config attributes, <meta> tags, and data-* attributes (useful for hx-live state later)
  • Global config.relaxedJSON option (defaults to true)
  • Fully backwards compatible with strict JSON (whether config.relaxedJSON is true or false)
  • 3-line regex-based implementation using JSON.parse (no eval)

Examples:

  <button hx-config='timeout: 5000, cache: "no-cache"'>
  <meta name="htmx:config" content='defaultSwap: "innerHTML", timeout: 30000'>

Users can disable globally with config.relaxedJSON = false for strict JSON-only mode.

Introduces htmx.parseJSON() method with optional relaxed syntax that accepts
unquoted object keys and auto-wraps bare properties in braces, making inline
attribute configurations significantly more readable.

Features:
- Unquoted keys: {timeout: 5000} instead of {"timeout": 5000}
- Auto-wrapping: timeout: 5000 instead of {timeout: 5000}
- Works in hx-config attributes, meta tags, and data-* attributes (useful for hx-live state)
- Global config.relaxedJSON option (defaults to true)
- Fully backwards compatible with strict JSON
- 3-line regex-based implementation using JSON.parse (no eval)

Examples:
  <button hx-config='timeout: 5000, cache: "no-cache"'>
  <meta name="htmx:config" content='defaultSwap: "innerHTML", timeout: 30000'>

Users can disable globally with config.relaxedJSON = false for strict JSON-only mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant