vendredi 6 mars 2015

split string into object

working on a little node script and I'm looking for the best way to tackle splitting a string up into an object.


I have strings that look like this:



key1 key2 "value"
key1 key2 key3 key4 key5 "value of something"
key1 "value can have special characters here too btw and theoretically even an double quote " mark."


etc.


what I am trying to do is convert the above into:



console.log(obj.key1.key2) //returns: value
console.log(obj.key1.key2.key3.key4.key5) //returns: value of something
console.log(obj.key1) //returns: value can have special characters here too btw and theoretically even an double quote " mark.


Basically the first quote and the last quote in the string contains the value and everything else (space delimited) are the keys tree.


Aucun commentaire:

Enregistrer un commentaire