A
A
alienstone2016-04-12 12:53:19
linux
alienstone, 2016-04-12 12:53:19

How to create and transform a directory tree into .json using bash?

Hello
How can I create and transform a directory tree into .json using bash?
I think the point is clear. Basically, I get recursively the paths of all the files in my directory. But then the problem arises: how to create a competent .json file from all this?
Tried to use JSHON - does not work.
help me please

Answer the question

In order to leave comments, you need to log in

3 answer(s)
X
xotkot, 2016-04-16
@alienstone

$ tree -J
if you need with full paths then:
$ tree -f -J

D
DuD, 2016-04-12
@DuD

Is it necessary to do this in bash? Try python, it will be much easier and clearer there.

A
abcd0x00, 2016-04-13
@abcd0x00

You need to write a couple of functions, one of which is recursive. One function is responsible for outputting a directory, and the other one is responsible for outputting a file. The directory function calls itself for directories and the file function for files. And the file function returns the path to the file.
You just display the file tree on the screen without any json using these functions. When it's done, you'll see where you need to insert parentheses, commas, and quotes to make json out of this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question