Skip to content

hx-vals + json-enc: first-level empty array is dropped #3845

Description

@metametadata

htmx.org 2.0.10, json-enc 2.0.3.

In my case this bug breaks some cases of the programmatic population of hx-vals. E.g. as in the example from the docs: hx-vals='js:{...foo()}' where foo() returns a map where some first-level value is [].

Steps

See https://jsfiddle.net/r4sgw3nh:

<script src="https://unpkg.com/htmx.org@2.0.10"></script>
<script src="https://unpkg.com/htmx-ext-json-enc@2.0.3/json-enc.js"></script>

<button type="button" hx-ext="json-enc" hx-post="/test" hx-vals='js:{
  "firstLevel": [],
  "secondLevel": {
    "values": []
  }
}'>
Click me
</button>
  1. Click Click me.
  2. Inspect the made request payload in the browser devtools.

Actual

{"secondLevel":{"values":[]}}

Expected

{"firstLevel":[],"secondLevel":{"values":[]}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions