T
T
Tech2020-10-09 11:17:51
linux
Tech, 2020-10-09 11:17:51

How to add word to jq filter output?

The filter collects new json:

jq '.comments[] | {comment:{url_slug:.post.url_slug, post_id:.post.id}}'

as:
{
  "comment": {
    "url_slug": "post-solar-system",
    "post_id": 555555
  }

How can I add a given constant word in front of the url, and substitute post_id at the end so that the filter output looks like this?
{
  "comment": {
    "url_slug": "post-solar-system",
    "post_id": 555555
    "full_url": "https://экзампл.ком/post-solar-system-555555/"
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2020-10-09
@bioid

Something like this

full_url:("https://example.com/" + .post.url_slug + "-" + (.post.id | tostring))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question