How to use jq streaming for processing large array of objects and convert into array of objects

The following response may be of interest in the case (contrary to the specifics of this particular question) that the output array is small enough to fit into memory.

One option would be to change the second invocation of jq to this form:

jq -nc '[inputs | .... ]'

The -n option here goes with inputs, and the outer square brackets put everything into an array.

Another possibility, again based on the above assumption, might be to combine the two calls to jq into one:

< data.json jq -cn --stream '
  [fromstream(1|truncate_stream(inputs))
   | if has ("middleName") then .sortableMiddleName=.middleName 
     else . end
     | if has("middleName") then .middleName=[.middleName] 
       else . end ]'