GithubHelp home page GithubHelp logo

Comments (4)

brainfoolong avatar brainfoolong commented on June 11, 2024

Hi. I cannot find an error here, can you post what your expected result should be? The object you've posted show exactly the values and names of your given input examples.

from form-data-json.

Nazar84 avatar Nazar84 commented on June 11, 2024

If I use fields with name index in 'correct' order like this:

<input type="hidden" name="Company[Phone][0][id]"         value="122"                   class="form-control" />
<input type="hidden" name="Company[Phone][0][phone]"  value="3339991111"     class="form-control" />

<input type="hidden" name="Company[Phone][1][id]"         value="125"                   class="form-control" />
<input type="hidden" name="Company[Phone][1][phone]"  value="33"                    class="form-control" />

I have got the result:

Phone => [
    {
      id => 122,
      phone => 3339991111,
    },{
      id => 125,
      phone => 33,
    },
],

At first example I receive hash of hashes. At this example I have array of hashes.

from form-data-json.

brainfoolong avatar brainfoolong commented on June 11, 2024

Hi, this is exactly what should happen. This library does create data out of input names, and when your input names are not "in order", it must create an object instead of a real array, because arrays cannot have "gaps" in the index numbers.

This library does not check or "assume" that the gap should be ignored and make an array out of it. It doesn't matter if the keys are numbered or have any other arbitrary value, it will be an object (hash you call it).

Real arrays only, and really only, can be produced when you have keys starting with zero and with no gaps in between. 0,1,2,3,4 is ok, 0,1,3,4,5 isn't.

You have to create correct names of inputs if you really want an array instead of an object.

It is no bug nor a feature that is supported by this library. It boils basically down to a previous feature request of you, manipulating data before/after the output. You have to do it your own way, when your data/input names is different to the things you need.

Btw. - Working without any key name [] will also not work here, as every empty key [] will increase index number in the result, which is also expected.

from form-data-json.

Nazar84 avatar Nazar84 commented on June 11, 2024

Thank You very much!

from form-data-json.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.