jqlang / jq

Command-line JSON processor

Home Page:https://jqlang.github.io/jq/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ignore comments when reading JSONs

netw0rkf10w opened this issue · comments

Hello,

In my script I have the following code for reading information from an input JSON:

# Iterate over each site in JSON
for site in $(jq -r '.sites[] | @base64' "$json_file"); do
    _jq() {
        echo ${site} | base64 --decode | jq -r ${1}
    }

    local_path=$(_jq '.localPath')
    remote_path=$(_jq '.remotePath')
    
    # Sync with remote server
    # echo "***" "$file_path" "$local_path" "$remote_path"
    sync_with_remote "$file_path" "$local_path" "$remote_path"
done

The issue is that if the JSON has comments:

{
// some comments
}

then it raises an error. Can jq ignore comments?

Thank you in advance for your answer!

See #1571.

See #1571.

Oh thanks! Woah, it took more than 6 years to have a first PR that is going to be merged. I didn't know it was that difficult for such a simple feature.

This is not that simple, the main issue is how to retain the comments with jq . reformatting JSON files with comments. Another issue is that the feature should be opt-in, because jq should behave strictly by default for validation use-case, but the current parser implementation makes it difficult to archieve. Closing as dup issub anyway.