Samuel Santiago
Samuel Santiago

Reputation: 47

BASH How to treat JSON inside a variable to remove only a specific part of the text

I have a big JSON inside a var and I need to remove only from that specific comma ( and I have incontable number of others comma before that ) until the penultimate Curly Brackets.. in short, Only the BOLD text..... ( text between ** and next ** )

edit

originally there is no ** in json, I put it in the code just to show where it starts and ends what I want to remove ##################################################

              }
        ]
    }**,
    "meta": {
        "timeout": 0,
        "priority": "LOW_PRIORITY",
        "validationType": "SAME_FINGERS",
        "labelFilters": [],
        "externalIDs": [
            {
                "name": "chaveProcesso",
                "key": "01025.2021.0002170"
            }
        ]
    }**
}

Upvotes: 0

Views: 128

Answers (1)

William Pursell
William Pursell

Reputation: 212208

It would help if you showed more context, but basically you want something like:

jq 'del(.meta)'

or:

jq 'with_entries(select(.key != "meta"))'

eg:

#!/bin/sh

json='{
    "foo": 5,
    "meta": {
        "timeout": 0,
        "priority": "LOW_PRIORITY",
        "validationType": "SAME_FINGERS",
        "labelFilters": [],
        "externalIDs": [
            {
                "name": "chaveProcesso",
                "key": "01025.2021.0002170"
            }
        ]
    }
}'

echo "$json" | jq 'del(.meta)'

Upvotes: 2

Related Questions