You're making it a lot more complicated than it is. Just use map() and |=:

jq 'map(.tags |= split(" "))' file.json

Edit:

If you want to handle entries without tags:

jq 'map(try(.tags |= split(" ")))' file.json

Alternatively, if you want to keep unchanged all entries without tags:

jq 'map(try(.tags |= split(" ")) // .)' file.json

Result:

[
  {
    "tags": [
      "tagA",
      "tag-B",
      "tagC"
    ],
    "title": "Some Title"
  },
  {
    "tags": [
      "tagA",
      "tagC"
    ],
    "title": "Some Title 2"
  }
]
Answer from Satō Katsura on Stack Exchange
🌐
Zendesk Developer Docs
developer.zendesk.com › documentation › integration-services › developer-guide › jq-cheat-sheet
jq cheat sheet | Zendesk Developer Docs
To create an array, wrap the output in square brackets ([]). The following expression combines the collaborator_ids and submitter_id properties into a single array. ... Use the index filter to get the index of the first occurrence of an element in an array. If the element doesn't exist in the ...
🌐
Qmacro
qmacro.org › blog › posts › 2022 › 05 › 06 › converting-strings-to-objects-with-jq
Converting strings to objects with jq - DJ Adams
May 6, 2022 - Moreover, given that I had the elements where I wanted them, in an outer array, it would seem sensible at this point onwards to express the transformations required via map, which (like map in other languages, I guess it's as much of a paradigm as it is a function or filter), takes an array and produces an array. So for example, I could replace each string with its length, while still keeping the structure, by passing the [.,inputs] into map like this: ... This would produce the following (note I've used the --compact-output (-c) option to save space here): ... In the modification requirements, I first had to remove the SAP-samples/ organisation name prefix, and I turned to sub for that, as I'm partial to the occasional regular expression: jq -R '[.,inputs] | map(sub("^.+/";""))' names.txt
Discussions

How to use jq to convert an bash array in command line to json array? - Unix & Linux Stack Exchange
@muru for those wondering -n, from ... as the input. This is useful when using jq as a simple calculator or to construct JSON data from scratch." ... There are two main ways to create a valid JSON array from arbitrary lists of strings.... More on unix.stackexchange.com
🌐 unix.stackexchange.com
December 15, 2022
Creating an array from objects?
First of all, kudos on such an excellent library...I've used jq for basic CLI tasks and have only recently delved into its more advanced functions, and am continually amazed at how things just ... More on github.com
🌐 github.com
7
January 29, 2015
How to convert string list to JSON string array in Bash? - Stack Overflow
The fact that [:-1] serves to suppress ... array element is surprising, given that even without it, interior lines are reported without their trailing \n, and, curiously, [:-1] doesn't trim an additional character from the end. Generally, split() employs separator logic rather than terminator logic. 2017-06-10T22:21:13.327Z+00:00 ... As this is primarily a jq question, I'd recommend using printf '%s' "$groups" instead of echo -n; then ... More on stackoverflow.com
🌐 stackoverflow.com
Raw lines to an array of lines?
Is there a way to convert multiline, non-JSON input to a JSON array of lines in one invocation of jq? Desired result: echo -en "foo\nbar\nbaz" | jq [ "foo", "bar", "baz" ] Failed attempts: $ echo -... More on github.com
🌐 github.com
9
August 28, 2014
🌐
jq recipes
remysharp.com › drafts › jq-recipes
jq recipes
April 16, 2024 - In this case, running Zeit's now ls | jq --raw-input --slurp to find out how many running instance I have: split("\n")[1:-3] | # split into an array of strings, removing the 1st and last few blank lines map([ split(" ")[] | select(.
🌐
Programming Historian
programminghistorian.org › en › lessons › json-and-jq
Reshaping JSON with jq | Programming Historian
May 24, 2016 - Both of these commands are wrapped in [] which tells jq to collect every result into one single array, which is passed with a | along to: join(";"), which turns that array into one single character string, with semicolon delimiters between multiple tweet ids. This filter created new JSON.
🌐
Jqlang
jqlang.github.io › jq › manual
jq 1.8 Manual
If no mutation is applied to this value then it will make to the output in its original form, even if conversion to double would result in a loss. As in JSON, [] is used to construct arrays, as in [1,2,3]. The elements of the arrays can be any ...
🌐
iO Flood
ioflood.com › blog › jq-array
Manipulating JSON Arrays with jq | Example Guide
November 15, 2023 - In this example, we’re using the echo command to create an empty array, and then we’re using jq to add an element to it. The '. += ["element"]' part of the command is where the magic happens. This is jq’s syntax for adding an element to an array.
Find elsewhere
🌐
Exercism
exercism.org › tracks › jq › concepts › arrays
Arrays in jq on Exercism
Use brackets to collect elements into an array. ... The elements of a stream can be captured into an array by enclosing it in brackets.
🌐
GitHub
github.com › jqlang › jq › issues › 684
Creating an array from objects? · Issue #684 · jqlang/jq
January 29, 2015 - First of all, kudos on such an excellent library...I've used jq for basic CLI tasks and have only recently delved into its more advanced functions, and am continually amazed at how things just work with few surprises...rare for a CLI tool that has so many features... So I think my question is pretty basic, and I'm missing something very obvious that could be clarified in the docs. Given a series of objects, what do I pipe them through to get them into an array?
Author   dannguyen
🌐
GitHub
github.com › jqlang › jq › issues › 563
Raw lines to an array of lines? · Issue #563 · jqlang/jq
August 28, 2014 - Is there a way to convert multiline, non-JSON input to a JSON array of lines in one invocation of jq? Desired result: echo -en "foo\nbar\nbaz" | jq [ "foo", "bar", "baz" ] Failed attempts: $ echo -...
Author   rfletcher
🌐
jq
jqlang.org › tutorial
Tutorial
If you want to get the output as a single array, you can tell jq to "collect" all of the answers by wrapping the filter in square brackets: jq '[.[] | {message: .commit.message, name: .commit.committer.name}]' Show resultHide result · [ { "message": "docs: Document repeat(exp)", "name": "Nico Williams" }, { "message": "Mention -n in IO-section and for input/inputs", "name": "Nico Williams" }, { "message": "Fix iteration problem for non decimal string\n\nWhen the string transformation to number failed, all following\ntransformation failed too.\n\nThis happend because status in decNumberFromString function is\nupdated just in error case.
🌐
Learn X in Y Minutes
learnxinyminutes.com › jq
Learn jq in Y Minutes
Feel free to look # them up in ... # averages, and finally generate a report. # echo $numbers | jq -rs ' # Slurp the numbers into an array. [ [ map(tostring) # Turn it into an array of strings....
🌐
GitHub
gist.github.com › olih › f7437fb6962fb3ee9fe95bda8d2c8fa4
jq Cheet Sheet · GitHub
-> % jq '[path(..)] | .[3] ' example.json [ "data", "object", "user" ] (ehsm-py3.9) cbongior@cbongior-mac [09:54:38] [~/dev/ehsm] [main *] -> % jq 'getpath([ "data", "object", "user" ])' example.json { "id": 1, "range": [ -255, 0, 255 ], "notation": "big-O", "details": { "lat": 0.000, "long": 0.000, "time": 42 } } (ehsm-py3.9) cbongior@cbongior-mac [09:55:03] [~/dev/ehsm] [main *] -> % jq '[path(..)] | .[3] | getpath' example.json jq: error: getpath/0 is not defined at <top-level>, line 1: [path(..)] | .[3] | getpath jq: 1 compile error (ehsm-py3.9) cbongior@cbongior-mac [09:55:25] [~/dev/ehsm] [main *] -> % jq '[path(..)] | .[3] | getpath(.)' example.json jq: error (at example.json:27): Cannot index array with string "data"
🌐
rOpenSci
docs.ropensci.org › jqr › reference › build.html
Build arrays and objects — build • jqr - Docs
build_array(.data, ...) build_array_(.data, ..., .dots) build_object(.data, ...) build_object_(.data, ..., .dots) ... input. This can be JSON input, or an object of class jqr that has JSON and query params combined, which is passed from function ...