rhalff / dot-object

Transform json objects using dot notation
MIT License
470 stars 46 forks source link

Support for arrays in dot notation #7

Open riaan53 opened 9 years ago

riaan53 commented 9 years ago

Hi,

Is it possible to convert the following back to an object in your example?

{
  "id": "my-id",
  "nes.ted.value": true,
  "other.nested.stuff": 5,
  "some.array.0": "A",
  "some.array.1": "B"
}

or something like:

{
  "id": "my-id",
  "nes.ted.value": true,
  "other.nested.stuff": 5,
  "some.array[0]": "A",
  "some.array[1]": "B"
}

to

var obj = {
  id: 'my-id',
  nes: { ted: { value: true } },
  other: { nested: { stuff: 5 } },
  some: { array: ['A', 'B'] }
};

Thank you.

Regards, Riaan

rhalff commented 9 years ago

It should!

Somehow it is not working however, so I will try to fix it later.

The arrays do not seem to be converted correctly.

rhalff commented 9 years ago

I've just added this to a new release 1.1

Both notation variants should now be working.

riaan53 commented 9 years ago

Awesome!

Thanks

jasonadkison commented 9 years ago

Thanks for adding this, however I'm having an issue, when removing an element from an array, the length doesn't update. Any pointers?

rhalff commented 9 years ago

@jasonadkison You have an example of the code you are using?

jasonadkison commented 9 years ago

@rhalff http://codepen.io/jadkison/pen/wKexOg

rhalff commented 9 years ago

Thanks a lot, I'll have a look at it.