Skip to main content
added 4 characters in body
Source Link
raylight
  • 541
  • 1
  • 8
  • 18

Let's say I use the command find "$HOME" -maxdepth 1 -type d and I get the following result:

/home/user/folder1
/home/user/folder2
/home/user/folder3
/home/user/folder4

I'd like to use jq on a pipe and create different JSON lines as the following result:

{ "path": "/home/user/folder1", "type":"directory"}
{ "path": "/home/user/folder2", "type":"directory"}
{ "path": "/home/user/folder3", "type":"directory"}
{ "path": "/home/user/folder4", "type":"directory"}

I expected to solve it with jq to avoid putting this list of folders inside an array and creating them one by one in a loop. In pseudo-code the idea would be:

find "$HOME" -maxdepth 1 -type d | jq '.logic-to-create-json-strings'

Is it possible to do with jq?

Let's I use the command find "$HOME" -maxdepth 1 -type d and I get the following result:

/home/user/folder1
/home/user/folder2
/home/user/folder3
/home/user/folder4

I'd like to use jq on a pipe and create different JSON lines as the following result:

{ "path": "/home/user/folder1", "type":"directory"}
{ "path": "/home/user/folder2", "type":"directory"}
{ "path": "/home/user/folder3", "type":"directory"}
{ "path": "/home/user/folder4", "type":"directory"}

I expected to solve it with jq to avoid putting this list of folders inside an array and creating them one by one in a loop. In pseudo-code the idea would be:

find "$HOME" -maxdepth 1 -type d | jq '.logic-to-create-json-strings'

Is it possible to do with jq?

Let's say I use the command find "$HOME" -maxdepth 1 -type d and I get the following result:

/home/user/folder1
/home/user/folder2
/home/user/folder3
/home/user/folder4

I'd like to use jq on a pipe and create different JSON lines as the following:

{ "path": "/home/user/folder1", "type":"directory"}
{ "path": "/home/user/folder2", "type":"directory"}
{ "path": "/home/user/folder3", "type":"directory"}
{ "path": "/home/user/folder4", "type":"directory"}

I expected to solve it with jq to avoid putting this list of folders inside an array and creating them one by one in a loop. In pseudo-code the idea would be:

find "$HOME" -maxdepth 1 -type d | jq '.logic-to-create-json-strings'

Is it possible to do with jq?

Rollback to Revision 3
Source Link
thanasisp
  • 8.5k
  • 2
  • 29
  • 40

Let's I use the command find "$HOME" -maxdepth 1 -type d and I get the following result:

/home/user/folder1
/home/user/folder2
/home/user/folder3
/home/user/folder4

I'd like to use jq on a pipe and create different JSON lines as the following result:

{ "path": "/home/user/folder1", "type":"directory"}
{ "path": "/home/user/folder2", "type":"directory"}
{ "path": "/home/user/folder3", "type":"directory"}
{ "path": "/home/user/folder4", "type":"directory"}

I know this output is not a valid JSON. I want the result to be as it is in this example with each line being a valid JSON by itself. I expected to solve it with jq to avoid putting this list of folders inside an array and creating them one by one in a loop. In pseudo-code the idea would be:

find "$HOME" -maxdepth 1 -type d | jq '.logic-to-create-json-strings'

Is it possible to do with jq?

Let's I use the command find "$HOME" -maxdepth 1 -type d and I get the following result:

/home/user/folder1
/home/user/folder2
/home/user/folder3
/home/user/folder4

I'd like to use jq on a pipe and create different JSON lines as the following result:

{ "path": "/home/user/folder1", "type":"directory"}
{ "path": "/home/user/folder2", "type":"directory"}
{ "path": "/home/user/folder3", "type":"directory"}
{ "path": "/home/user/folder4", "type":"directory"}

I know this output is not a valid JSON. I want the result to be as it is in this example with each line being a valid JSON by itself. I expected to solve it with jq to avoid putting this list of folders inside an array and creating them one by one in a loop. In pseudo-code the idea would be:

find "$HOME" -maxdepth 1 -type d | jq '.logic-to-create-json-strings'

Is it possible to do with jq?

Let's I use the command find "$HOME" -maxdepth 1 -type d and I get the following result:

/home/user/folder1
/home/user/folder2
/home/user/folder3
/home/user/folder4

I'd like to use jq on a pipe and create different JSON lines as the following result:

{ "path": "/home/user/folder1", "type":"directory"}
{ "path": "/home/user/folder2", "type":"directory"}
{ "path": "/home/user/folder3", "type":"directory"}
{ "path": "/home/user/folder4", "type":"directory"}

I expected to solve it with jq to avoid putting this list of folders inside an array and creating them one by one in a loop. In pseudo-code the idea would be:

find "$HOME" -maxdepth 1 -type d | jq '.logic-to-create-json-strings'

Is it possible to do with jq?

added 27 characters in body
Source Link
raylight
  • 541
  • 1
  • 8
  • 18

Let's I use the command find "$HOME" -maxdepth 1 -type d and I get the following result:

/home/user/folder1
/home/user/folder2
/home/user/folder3
/home/user/folder4

I'd like to use jq on a pipe and create different JSON lines as the following result:

{ "path": "/home/user/folder1", "type":"directory"}
{ "path": "/home/user/folder2", "type":"directory"}
{ "path": "/home/user/folder3", "type":"directory"}
{ "path": "/home/user/folder4", "type":"directory"}

I know this output is not a valid JSON. I want the result to be as it is in this example with each line being a valid JSON by itself. I expected to solve it with jq to avoid putting this list of folders inside an array and creating them one by one in a loop. In pseudo-code the idea would be:

find "$HOME" -maxdepth 1 -type d | jq '.logic-to-create-json-strings'

Is it possible to do with jq?

Let's I use the command find "$HOME" -maxdepth 1 -type d and I get the following result:

/home/user/folder1
/home/user/folder2
/home/user/folder3
/home/user/folder4

I'd like to use jq on a pipe and create different JSON lines as the following result:

{ "path": "/home/user/folder1", "type":"directory"}
{ "path": "/home/user/folder2", "type":"directory"}
{ "path": "/home/user/folder3", "type":"directory"}
{ "path": "/home/user/folder4", "type":"directory"}

I expected to solve it with jq to avoid putting this list of folders inside an array and creating them one by one in a loop. In pseudo-code the idea would be:

find "$HOME" -maxdepth 1 -type d | jq '.logic-to-create-json-strings'

Is it possible to do with jq?

Let's I use the command find "$HOME" -maxdepth 1 -type d and I get the following result:

/home/user/folder1
/home/user/folder2
/home/user/folder3
/home/user/folder4

I'd like to use jq on a pipe and create different JSON lines as the following result:

{ "path": "/home/user/folder1", "type":"directory"}
{ "path": "/home/user/folder2", "type":"directory"}
{ "path": "/home/user/folder3", "type":"directory"}
{ "path": "/home/user/folder4", "type":"directory"}

I know this output is not a valid JSON. I want the result to be as it is in this example with each line being a valid JSON by itself. I expected to solve it with jq to avoid putting this list of folders inside an array and creating them one by one in a loop. In pseudo-code the idea would be:

find "$HOME" -maxdepth 1 -type d | jq '.logic-to-create-json-strings'

Is it possible to do with jq?

added 27 characters in body
Source Link
raylight
  • 541
  • 1
  • 8
  • 18
Loading
deleted 16 characters in body
Source Link
raylight
  • 541
  • 1
  • 8
  • 18
Loading
Source Link
raylight
  • 541
  • 1
  • 8
  • 18
Loading