JSONify icon indicating copy to clipboard operation
JSONify copied to clipboard

Support to Jsonify and Dejsonify complex JSON structures

Open danieldestro opened this issue 7 years ago • 4 comments

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?

danieldestro avatar Dec 01 '17 11:12 danieldestro

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:

kushalpandya avatar Dec 01 '17 15:12 kushalpandya

Thanks. I found two other libraries that helped me: jsForm and transForm.

danieldestro avatar Dec 01 '17 16:12 danieldestro

Hi, can i jsonify 'disabled' inputs? :)

n4ks avatar Nov 28 '18 13:11 n4ks

@n4ks Yes it should be possible as long as field has name attribute present and is unique.

kushalpandya avatar Dec 03 '18 14:12 kushalpandya