This answer assumes that your filenames (or whatever text you wish to JSON encode) is valid UTF-8.
Two alternatives:
Not using xargs: Call jq with the pathnames as positional parameters directly from find with -exec. Read the found pathnames with --args and access them as the array $ARGS.positional[]positional in the jq expression. For each pathname, create a JSON object.
find "$HOME" -maxdepth 1 -type d \
-exec jq --null-inputn --compact-outputc \
'$ARGS.positional[] as $path | { path: $path, type: "directory" }' \
--args {} +
Using xargs: Use -print0 with find and -0 with xargs to safely pass the found pathnames from find to xargs. The jq expression is identical to the above, only the manner in whichhow the pathnames are passed between find and jq differs.
find "$HOME" -maxdepth 1 -type d -print0 |
xargs -0 jq --null-inputn --compact-outputc \
'$ARGS.positional[] as $path | { path: $path, type: "directory" }' --args
With both approaches above, jq would encode the found pathnames toso that they can be able to represent themrepresented as JSON strings.
An alternative jq expression, with the same effect as
$ARGS.positional[] as $path | { path: $path, type: "directory" }
is
$ARGS.positional | map({ path: ., type: "directory" })[]
To read lines into a set of objects likeas you show, you may use the following jq command, which reads from its standard input stream:
jq -R -c '{ path: ., type: "directory" }'