Hi there,
I am having trouble with what I believe is a very simple problem. I have a text file which looks like this:
Cat 1
Sub Cat 1
Sub Cat 2
Sub Cat 3
Testing
Cat 2
Sub Cat 1
Nested item
Another nested item
Nested-nested item
Nested-nested item 2
Yet another nested item
Sub Cat 2
Sub Cat 3
The lines end in \n and four spaces represent a tab (\t - I couldn't add tabs here). I am trying to convert this list of items into a nested array with a similar structure to that of a file system.
Ideally, the result should look something like this:
{"Cat 1": {
"Sub Cat 1",
"Sub Cat 2",
{"Sub Cat 3": {"Testing"}}
},
"Cat 2": {
{"Sub Cat 1": {"Nested item",
{"Another nested item": {"Nested nested item", "Nested nested item 2"}},
"Yet another nested item"},
"Sub Cat 2",
"Sub Cat 3"}
}
Afterwards, I would like to convert the nested array into both JSON and CSV format to be written to the file system. Please feel free to change the format of the result and nested results, so long as they can be outputted correctly.
I am having trouble with what I believe is a very simple problem. I have a text file which looks like this:
Cat 1
Sub Cat 1
Sub Cat 2
Sub Cat 3
Testing
Cat 2
Sub Cat 1
Nested item
Another nested item
Nested-nested item
Nested-nested item 2
Yet another nested item
Sub Cat 2
Sub Cat 3
The lines end in \n and four spaces represent a tab (\t - I couldn't add tabs here). I am trying to convert this list of items into a nested array with a similar structure to that of a file system.
Ideally, the result should look something like this:
{"Cat 1": {
"Sub Cat 1",
"Sub Cat 2",
{"Sub Cat 3": {"Testing"}}
},
"Cat 2": {
{"Sub Cat 1": {"Nested item",
{"Another nested item": {"Nested nested item", "Nested nested item 2"}},
"Yet another nested item"},
"Sub Cat 2",
"Sub Cat 3"}
}
Afterwards, I would like to convert the nested array into both JSON and CSV format to be written to the file system. Please feel free to change the format of the result and nested results, so long as they can be outputted correctly.