0

I'm receiving objects structured like this example:

{name: "Example", fruit.apples: true, "soil.tree.leaf": "nature" }

I need a function that can converted it to this:

{name: "Example", fruit: { apples: true }, soil: { tree: { leaf: "nature" }}}
Rob B
  • 1,514
  • 3
  • 23
  • 38
  • That's a syntax error. What exactly do you receive? – Bergi Dec 09 '15 at 21:51
  • In this situation you'll just have to fix the data at the source, because it's broken. – Sam Dec 09 '15 at 21:55
  • I expect the data is fine. If it's delivered as JSON (`'{"name": "Example", "fruit.apples": true, "soil.tree.leaf": "nature" }'`) then it will produce a clean object when it's parsed. The keys can be accessed with square notation. – Andy Dec 09 '15 at 21:57
  • My bad, forgot the to make the key a string. – Rob B Dec 09 '15 at 21:57
  • Thanks Bergi, had tried looking for a similar issue. – Rob B Dec 09 '15 at 22:03
  • @RobB: Glad to have helped. Also look around the "Linked questions" in the side bar, there are many similar questions – Bergi Dec 09 '15 at 22:14

0 Answers0