I’m trying to make a small parser which receives the json string and the path to get:
var args = process.argv;
var jsonToBeParsed = args[2];
var path = args[3];
var result = JSON.parse(jsonToBeParsed);
console.log(result);
console.log(result.path);
I’m calling this with
node parser.js '{"asd":"123", "qwe":"312"}' 'asd'
It gives me undefined
I think it has to be done with some eval function but I don’t have too much experience with node/JS.
How can I resolve this?, I need to get the result from the command line.
Edit: I’m expecting “123” in the second log. Thanks @Esailija, the question wasn’t too clear …
I think you are trying to use dynamic property, you cannot use
.path, because that literally means.pathproperty.Try this:
if
path === "asd", then it will work, which is statically equivalent toresult["asd"]orresult.asd