Wednesday, 24 May 2017

Build nested JSON from string of nested keys

I have csv files that I am reading using nodeJS. I convert each file to text before reading.

Each line in the file have data delimited with '='.

Each line looks something like

data.location.degree.text=sometexthere

The first portion before the "=" represent an index to a json object in my app. I aim to parse this data and build a json representation of it so that the line above becomes

data:{ location:{ degree:{ text: 'sometexthere' } } }

Using javascript/ node js; How can I convert a string which is supposed to represent a sequence of nested JSON keys, into a json object like above?



via C Scott

No comments:

Post a Comment