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

How can I replace the value if the key name is with a dot? #159

Open
andrew-clear opened this issue Apr 13, 2022 · 2 comments
Open

How can I replace the value if the key name is with a dot? #159

andrew-clear opened this issue Apr 13, 2022 · 2 comments

Comments

@andrew-clear
Copy link

As I understand, I can replace value via this command:
json -I -f test.json -e "this.name='andrew'"
But how can I replace a value for this key -> last.name?
I mean when I try to replace the value via this command
json -I -f test.json -e "this.last.name='andrew'"
I got:

undefined:3
this.last.name='andrew'
              ^

TypeError: Cannot set properties of undefined (setting 'name')
    at Object.eval (eval at main (/usr/local/lib/node_modules/json/lib/json.js:1365:27), <anonymous>:3:15)
    at parseChunk (/usr/local/lib/node_modules/json/lib/json.js:1569:29)
    at /usr/local/lib/node_modules/json/lib/json.js:1426:13
    at getInput (/usr/local/lib/node_modules/json/lib/json.js:738:17)
    at main (/usr/local/lib/node_modules/json/lib/json.js:1396:9)
    at Object.<anonymous> (/usr/local/lib/node_modules/json/lib/json.js:1764:5)
@w4ss1m9797
Copy link

same prob her ...

@AlaaEddineCharbib
Copy link

this should work
json -I -f test.json -e 'this["last.name"]="andrew"'

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

3 participants