Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore comments when reading JSONs #3041

Closed
netw0rkf10w opened this issue Feb 13, 2024 · 3 comments
Closed

Ignore comments when reading JSONs #3041

netw0rkf10w opened this issue Feb 13, 2024 · 3 comments
Labels

Comments

@netw0rkf10w
Copy link

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!

@itchyny
Copy link
Contributor

itchyny commented Feb 13, 2024

See #1571.

@itchyny itchyny added the dup label Feb 13, 2024
@netw0rkf10w
Copy link
Author

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.

@itchyny
Copy link
Contributor

itchyny commented Feb 13, 2024

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.

@itchyny itchyny closed this as completed Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants