I have an Powershell Azure function that receives a (json) string as request body. I need to access the values of XMLA_String, WorkspaceId, and DatasetId in order to set them to variables. Please let me know how
The following body is received:
"{\"XMLA_String\":'{\"refresh\":{\"type\":\"full\",\"objects\":[{\"database\":\"<db>\",\"table\":\"<tab>\"}]}}',
\"WorkspaceId\":'<workspaceid>',
\"DatasetId\":'<datasetid>'}"
CodePudding user response:
Assuming that the line breaks in your sample JSON are just a formatting artifact, it looks like you're getting doubly JSON-encoded data, strangely.
Therefore, try applying ConvertFrom-Json twice (which you've since confirmed solved your problem):
# Sample response received.
$json = @'
"{\"XMLA_String\":'{\"refresh\":{\"type\":\"full\",\"objects\":[{\"database\":\"<db>\",\"table\":\"<tab>\"}]}}',\"WorkspaceId\":'<workspaceid>',\"DatasetId\":'<datasetid>'}"
'@
$json | ConvertFrom-Json | ConvertFrom-Json
The above outputs a [pscustomobject] instance with properties XMLA_String, WorkspaceId, and DatasetId:
XMLA_String WorkspaceId DatasetId
----------- ----------- ---------
{"refresh":{"type":"full","objects":[{"database":"<db>","table":"<tab>"}]}} <workspaceid> <datasetid>
