
Ask HN: Best way to turn plain text tab-indented list into JSON? - nkkollaw
I have a list of unknown depth in plain text, where the levels are represented by tabs.<p>Something like this:<p><pre><code>    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
</code></pre>
What is the most efficient way to turn this into a JSON array (ideally in JavaScript)?<p>Of course, I could go line by line, have a currIndentation variable and create an array, but I&#x27;m wondering if there is a better way.
======
DamonHD
If 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
Yes, 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...

