New to learning powershell here, open to any solution really as long as its self contained within the given script
It's really hard finding anything in the docs about this, which maybe means there isn't anything?
PSVersion 5.1
Build Version: 10.0.17134
No particular JSON standard or file setup will be known, but we can use this for an example:
{
"foo" : ["foo1", "foo2", "foo3"],
"bar" : {
"bar-foo" : 20,
"bar-bar" : {
"bar-bar-foo : "here"
}
}
}
I would like to simply navigate to a JSON KVP directly, as I will know the property before hand, and it's full nested path.
For example, input argument would be:
.\ScriptName -JsonProp ["bar"]["bar-bar"]["bar-bar-foo"]
My script is currently using ConvertTo-Json and the source is any given .json file, but if there is an easier or more friendly way to explicitly navigate a json object I'm all ears.
Goal is to change the value of that property and write it out to file
$json = Get-Content -Raw -Path $path | ConvertFrom-Json
$json.$JsonProp = "there"
As far as I can tell, the Json object has to use dot notation, but I've tried that with strings with no resolve, splitting the parameter for example:
.\ScriptName -JsonProp bar.bar-bar.bar-bar-foo
$json.$JsonProp = "there"
While I'm on the topic if you have any recommendations for literature on powershell please let me know.