JSONify
JSONify copied to clipboard
Support to Jsonify and Dejsonify complex JSON structures
Can I use "dots" in the form field name to (de)serialize a more complex JSON structure? For example, if I want to send a JSON like this to my REST Service:
{
id: 1,
name: "Daniel",
telephones: ["12345", "678901"],
addresses: [
{id: 1, city: "Sao Paulo", street: "Av. Paulista", zipcode: "999"},
{id: 2, city: "Rio de Janeiro", street: "Av. Brasil", zipcode: "333"}
]
}
I would like to create a form like this:
<form id="frm-person">
<input type="hidden" name="id">
Name: <input type="text" name="name">
Telephones:
Home: <input type="text" name="telephones">
Mobile: <input type="text" name="telephones">
Home Address:
<input type="hidden" name="addresses.id">
<input type="text" name="addresses.city">
<input type="text" name="addresses.street">
<input type="text" name="addresses.zipcode">
Work Address:
<input type="hidden" name="addresses.id">
<input type="text" name="addresses.city">
<input type="text" name="addresses.street">
<input type="text" name="addresses.zipcode">
</form>
Is it possible with your library?
I haven't tested it, but in such complex forms, I'd suggest to keep field names unique and then manually compose array of objects, as idea of jsonify is to be minimal and covering all the cases is only going to increase library size. :slightly_smiling_face:
Thanks. I found two other libraries that helped me: jsForm and transForm.
Hi, can i jsonify 'disabled' inputs? :)
@n4ks Yes it should be possible as long as field has name
attribute present and is unique.