-4

I'd like to process many json objects with one json object per line. Is it possible to let jq process each line as a separate json object instead of the whole file as a single json object? Thanks.

user1424739
  • 11,937
  • 17
  • 63
  • 152
  • 1
    This sounds like an xy problem. What's your use case? – Rafael Mar 02 '20 at 02:10
  • You seem to be accumulating quite a few downvotes, most likely because you have not followed the [mcve] guidelines. (If you had, you most likely would have answered your own question!) It's not too late though. – peak Mar 02 '20 at 05:19
  • Please show me how to make MWE in this case. I don’t think this is possible for this question. As the point is that I do know how to do it. If I don’t know it, how to make an example. – user1424739 Mar 02 '20 at 05:31
  • You could give an example of your JSONL data, with an example of the output you expect. You could then run some jq command, even if it’s just `jq .` – peak Mar 02 '20 at 06:06
  • The problem is those details don’t matter. Any specific example make it less general than the original question wants to ask. – user1424739 Mar 02 '20 at 06:08

1 Answers1

2

I'd like to process many json objects with one json object per line. Is it possible to let jq process each line as a separate json object ...

jq does that out-of-the-box. (The JSON entities provided as input do not have to be on separate lines, but it's fine if they are.)

The more interesting question is what can be done if the input consists of an array that is too large to fit in memory. If that is the problem, see Use jq to convert json array to jsonl format

peak
  • 105,803
  • 17
  • 152
  • 177
  • My question is what if the input is jsonl. I only see how to make the output jsonl. – user1424739 Mar 02 '20 at 05:21
  • If the input is already jsonl, there is nothing you have to do beyond deciding what specific problem you are trying to solve. As mentioned in a separate comment, if you took the time to follow the [mcve] guidelines, you'll most likely answer your own question. – peak Mar 02 '20 at 05:30
  • I don’t understand. Does jq support jsonl format? I only see it support json format but not jsonl format. – user1424739 Mar 02 '20 at 05:32
  • Yes, it supports jsonl, as already stated. – peak Mar 02 '20 at 05:46