![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
htmx-ext-form-json
Advanced tools
An HTMX extension for automatic type conversion in form data encoding. automatically converts values based on input types, ensuring correct data representation in JSON without requiring additional attributes or configuration.
This is an HTMX extension that enables the transformation of form data into a structured JSON object. The extension supports the HTML JSON form specification and works seamlessly with all examples outlined in the standard.
.
) or bracket ([]
) notation.htmx
: Integrates with htmx
events to set appropriate headers and handle form submissions.Add the JavaScript file to your project and include it in your HTML:
<script src="https://unpkg.com/htmx-ext-form-json"></script>
Enable the extension in your htmx configuration:
<form hx-ext="form-json" hx-post="/test">
...
</form>
The extension automatically serializes form data
into JSON
for any form with the hx-ext="form-json"
attribute. The resulting JSON object adheres to the HTML JSON form standard, supporting nested objects and arrays.
<form hx-ext="form-json" hx-post="/test">
<input name="name" type="text" value="John" />
<input name="age" type="number" value="30" />
<input name="boolean" type="checkbox" checked />
<input name="list" type="number" value="1">
<input name="list" type="number" value="2">
<input name="list" type="number" value="3">
</form>
<!-- Submission:
{
"name": "John",
"age": 30,
"boolean": true,
"list": [1, 2, 3]
}
-->
<form hx-ext="form-json" hx-post="/test" hx-vals="{"customValue": 87}">
<input name="pet.species" value="Dahut">
<input name="pet[name]" value="Hypatia">
<input name="data.person[2].name" value="Bob">
<input name="data.person.0.name" value="Alice">
</form>
<!-- Submission:
{
"customValue": 87,
"pet": {
"species": "Dahut",
"name": "Hypatia"
},
"data": {
"person": [
{ "name": "Alice" },
null,
{ "name": "Bob" }
]
}
}
-->
The algorithm does not lose data in that every piece of information ends up being submitted. But given the path syntax, it is possible to introduce clashes such that one may attempt to set an object, an array, and a scalar value on the same key.
<form hx-ext="form-json" hx-post="/test">
<input name="mix" value="scalar">
<input name="mix[0]" value="array 1">
<input name="mix[2]" value="array 2">
<input name="mix.key" value="key key">
<input name="mix[car]" value="car key">
</form>
<!-- Submission:
{
"mix": {
"": "scalar",
"0": "array 1",
"2": "array 2",
"key": "key key",
"car": "car key"
}
}
-->
an array irrespective of the number of its items, and without resorting to indices, one may use the append notation (only as the final step in a path)
<form hx-ext="form-json" hx-post="/test">
<input name="highlander[]" value="one">
<input name="highlander[]" value="twe">
</form>
<!-- Submission:
{
"highlander": ["one", "twe"]
}
-->
<form hx-ext="form-json" hx-post="/test">
<input name="wow.such[deep][3][much].power[!]" value="Amaze">
</form>
<!-- Submission:
{
"wow": {
"such": {
"deep": [
null,
null,
null,
{
"much": {
"power": {
"!": "Amaze"
}
}
}
]
}
}
}
-->
Optional attribute to skip parsing keys to struct:
<form hx-ext="form-json" hx-post="/test" ignore-deep-key >
<input name="wow.such[deep][3][much][power][!]" value="Amaze">
</form>
<!-- Submission:
{
"wow.such[deep][3][much][power][!]": "Amaze"
}
-->
To contribute, clone the repository and submit pull requests for features or bug fixes. Ensure all new functionality aligns with the HTML JSON form standard.
This project is licensed under the GNU GENERAL PUBLIC LICENSE V3. See the LICENSE file for details.
FAQs
An HTMX extension for automatic type conversion in form data encoding. automatically converts values based on input types, ensuring correct data representation in JSON without requiring additional attributes or configuration.
The npm package htmx-ext-form-json receives a total of 161 weekly downloads. As such, htmx-ext-form-json popularity was classified as not popular.
We found that htmx-ext-form-json demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.