Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work with ASP.NET MVC naming conventions #129

Open
Merenia opened this issue Oct 23, 2023 · 5 comments
Open

Doesn't work with ASP.NET MVC naming conventions #129

Merenia opened this issue Oct 23, 2023 · 5 comments

Comments

@Merenia
Copy link

Merenia commented Oct 23, 2023

I tried to use this library to serialize a complex form into json to send it as model in my controller but the list items are not serialized correctly.

Name exemple : foo.bar[0].prop
Serialization :
"foo.bar" : { "0.prop" : "value1", "1.prop" : "value2", "2.prop" : "value3", }

Should be :
"foo" : { "bar" : [ {"prop" : "value1"}, {"prop": "value2"}, {"prop": "value3"} ] }

@marioizquierdo
Copy link
Owner

It seems you expect the plugin to handle a different syntax. This plugin works with the syntax key[nested][nested].

Instead of key.nested.nested:

name="foo.bar.[0].prop"

This plugin uses key[nested][nested]:

name="foo[bar][0][prop]"

In addition, you need to tell the plugin to interpret the numbers as array indexes with the option useIntKeysAsArrayIndex:

$(myform).serializeJSON({useIntKeysAsArrayIndex: true});

This will produce the expected serialization.

Is is possible to serialize the with the dot syntax key.nested.nested?

Currently not. But I am open to a pull request suggestion to incorporate this syntax with an option like {dotSyntax: true}. It seems this could be implemented without much effort on the internal method splitInputNameIntoKeysArray. Thanks!

@Merenia
Copy link
Author

Merenia commented Oct 24, 2023

Hi,
I see your point.
However, the syntax used by ASP.NET MVC follows a standard used by all C# developers. I think it would be useful to include this support.
For your information, I've found another library that supports this syntax.
Nevertheless, I'd like to thank you for your work, which has undoubtedly helped a lot of people.

@muhlisatac
Copy link

For your information, I've found another library that supports this syntax.

Can you please share which library is it? Couse I have the same issue.

@GuillaumeMiet
Copy link

For your information, I've found another library that supports this syntax.

Can you please share which library is it? Couse I have the same issue.

Here is the repo :
https://github.com/raphaelm22/jquery.serializeToJSON

@muhlisatac
Copy link

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

No branches or pull requests

4 participants