X
X
xotkot2016-07-22 14:56:57
bash
xotkot, 2016-07-22 14:56:57

How to add an element inside an array in json using jq?

using the jq tool, you need to add an element to the array, for example:
from {"a":1,"b":[1,2]} you need to get {"a":1,"b":[1,2,3]}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xotkot, 2016-07-23
@xotkot

пока получился такой вариант:

$ echo '{"a":1,"b":[1,2]}' | jq -c '. + {b:(.b + [3])}'
{"a":1,"b":[1,2,3]}

если есть ещё варианты, пишите

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question