3 ms·
Ask HN: Best way to turn plain text tab-indented list into JSON?
I have a list of unknown depth in plain text, where the levels are represented by tabs.
Something like this:
item 1
item 1.1
item 1.2
item 2
item 2.1
item 2.2
item 2.2.1
item 2.2.2
item 3
What is the most efficient way to turn this into a JSON array (ideally in JavaScript)?
Of course, I could go line by line, have a currIndentation variable and create an array, but I'm wondering if there is a better way.
- DamonHD 9y agoIf feels to me like it's half-way to YAML (ie JSON superset) already. Maybe you can open a new [ array for each extra indent and close for each reduction in indent to take that part at least.
- nkkollaw 9y agoYes, I actually almost used YAML but tabs only were simpler. So, you're saying that I could turn it into YAML and then use any YAML parser. That's a really good idea. I think I can just add a dash character to each line before the last tab character (if any) and I'd have YAML...