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

Please have an example assigning values to JSON object #89

Closed
yookoala opened this issue Aug 2, 2021 · 1 comment
Closed

Please have an example assigning values to JSON object #89

yookoala opened this issue Aug 2, 2021 · 1 comment

Comments

@yookoala
Copy link

yookoala commented Aug 2, 2021

Please provide an example for JSON object assignment. Something equivalent to this:

npx jq '.scripts.build = "sass --load-path=./scss ./scss/style.scss:./css/style.css"' package.json

That is to add a value to json like this:

{
  "name": "some-library",
  "version": "1.0.0",
  "scripts": {
    "test": "some test"
  },
}

And turn it into this:

{
  "name": "some-library",
  "version": "1.0.0",
  "scripts": {
    "build": "sass --load-path=./scss ./scss/style.scss:./css/style.css",
    "test": "some test"
  },
}

There is no example or guide how to reference a value in the existing JSON object input. Would really know how to do it. Thanks.

@FGRibreau
Copy link
Owner

FGRibreau commented Aug 4, 2021

jq.node 'tap(x => x.scripts.build= "sass --load-path=./scss ./scss/style.scss:./css/style.css")' < package.json

with package.json being:

{
  "name": "some-library",
  "version": "1.0.0",
  "scripts": {
    "test": "some test"
  }
}

output is:

{
  "name": "some-library",
  "version": "1.0.0",
  "scripts": {
    "test": "some test",
    "build": "sass --load-path=./scss ./scss/style.scss:./css/style.css"
  }
}

Enjoy 👍

  • README.md updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants