Hi Dave,
To recap:
normally I do:
$ServerData = ‘{“data”: {“source”: “nrpe”, “tag”: [“OS”], “parents”: , “address”: [“10.0.0.0”],“hostname”: “server”,“hosttype”: “server”}}’ | convertto-json
And the result in $serverData is perfect to use for curl:
“{"data": {"source": "nrpe", "tag": ["OS"], "parents": , "address": ["10.0.0.0"],"hostname": "server","hosttype": "server"}}”
In the new process I remove data by doing the following:
$ServerData = ‘{“data”: {“source”: “nrpe”, “tag”: [“OS”], “parents”: , “address”: [“10.0.0.0”],“hostname”: “server”,“hosttype”: “server”}}’ | convertto-json
$ServerJson = $ServerData | ConvertFrom-Json
$ServerJson.data = $ServerJson.data | Select-Object * -ExcludeProperty source, hostname | ConvertTo-Json
Now $serverJson.data is in this format:
{
“tag”: [
“OS”
],
“parents”: [
],
"address": [
"10.0.0.0"
],
"hosttype": "server"
}
The last step in this I need to do is convert this back to:
“{"data": {"tag": ["OS"], "parents": , "address": ["10.0.0.0"],"hosttype": "server"}}”
I have been through the trials and tribulations of trying to replace charaters and such in the past which has not always worked, so I would really like to do this with a conversion of some sort.
I am just not clear on how I can get the $serverjson.data back to the desired format with the escape characters.
Do you have any ideas?
Thanks!