Logic apps: How to add root node in JSON variable? - json

I am trying to do the following:
#xml(json(concat('\\"rootnode\\":',variables('TestJSON'))))
However the error I am getting is :
InvalidTemplate. Unable to process template language expressions in
action 'Set_XXXXXXX' inputs at line '1' and column '1873': 'The
template language function 'json' parameter is not valid. The provided
value '\"rootnode\":.......... cannot be parsed: 'Unexpected
character encountered while parsing value: \. Path '', line 0,
position 0.'.
Looks like escape character is not working in Logic Apps? Any suggestions?

Please use this expression:
xml(json(concat('{"rootnode":',variables('TestJSON'), '}')))

Related

JSON-over-HTTP LLD fails with name contains invalid character '{'

I'm trying to configure a simple Host LLD from JSON over HTTP source, like this one: https://pastebin.com/raw/YWWxGs7y
It uses Preprocessing step with JSONpath (I can test it with built-in testing tool) and 3 LLD-macros which are JSONPaths, too. I test them with output (Result) JSON from built-in testing tool and https://jsonpath.com/
My LLD fails with multiple errors:
Cannot create host "{#LOCATION_ID}": name contains invalid character '{'.
Cannot create host "{#LOCATION_ID}": name contains invalid character '{'.
Cannot create host "{#LOCATION_ID}": name contains invalid character '{'.
Cannot create host "{#LOCATION_ID}": name contains invalid character '{'.​
...
I guess that LLD-Macro's value remains empty, but I have no idea how to check and solve this
My Template in Yaml https://pastebin.com/raw/bBHuJgEz
PS reposted from zabbix forum
I believe the correct macro could be:
lld_macro_paths:
-
lld_macro: '{#LOCATION_ID}'
path: '$.id'
-
lld_macro: '{#LOCATION_NAME}'
path: '$.name'
-
lld_macro: '{#LOCATION_TYPE}'
path: '$.type'

Not able to read json file in JMETER

I am trying to read json's from a text file using below command:
{__FileToString((${JSON_FILE},,)).replaceAll(' ','')}
File not readable.
Error: {"timestamp":1586945558777,"status":400,"error":"Bad Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"Could not read document: Unexpected character ('' (code 95)): was expecting double-quote to start field name\n at [Source: java.io.PushbackInputStream#6df97f39; line: 1, column: 3]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character ('' (code 95)): was expecting double-quote to start field name\n at [Source: java.io.PushbackInputStream#6df97f39; line: 1, column: 3]","path":"/service"}
I have gone through all related posts too but still not able to find the solution to it. Please can anyone help.
Refereneces:
JMeter - How to read JSON file?
https://devqa.io/perf/jmeter-send-json-file-as-request-in-body
https://www.360logica.com/blog/how-to-use-http-request-to-send-multiple-json-files
Thanks,
Mrinalini
The correct syntax would be:
${__strReplace(${__FileToString(${JSON_FILE})}, ,,)}
You cannot append normal Java functions like String.replaceAll() to JMeter Functions, if you want to get rid of whitespace characters you need to invoke __strReplace() function like shown above (this function is a Custom JMeter Function, it can be installed using JMeter Plugins Manager)
If you cannot use JMeter Plugins for some reason you can achieve the same using __groovy() function like:
${__groovy(new File(vars.get('JSON_FILE')).text.replaceAll(' '\, ''),)}
Demo:

ARM.Template from bash-script. Unterminated string. Expected delimiter:

I am writing a bash-script for uploading certificate from a linux-server to azure keyvault using the "armclient"
I follow this guide on how to use the armclient:
https://blogs.msdn.microsoft.com/appserviceteam/2016/05/24/deploying-azure-web-app-certificate-through-key-vault/
The command i want to perform is this:
ARMClient.exe PUT /subscriptions/<Subscription Id>/resourceGroups/<Server Farm Resource Group>/providers/Microsoft.Web/certificates/<User Friendly Resource Name>?api-version=2016-03-01 "{'Location':'<Web App Location>','Properties':{'KeyVaultId':'<Key Vault Resource Id>', 'KeyVaultSecretName':'<Secret Name>', 'serverFarmId':'<Server Farm (App Service Plan) resource Id>'}}"
I have created a string that populates all the fields required:
putparm=$resolved_armapi" \"{'Location':'$resolved_locationid','Properties':{'KeyVaultId':'$resolved_keyvaultid','KeyVaultSecretName':'$certname','serverFarmId':'$resolved_farmid'}}"\"
When i echo the output of the variable putparm, the result looks as expected (X-ed out names/ids):
/subscriptions/f073334f-240f-4261-9db5-XXXXXXXXXXXXX/resourceGroups/XXXXXXXX/providers/Microsoft.Web/certificates/XXXX-XXXXX-XXXXX?api-version=2016-03-01 "{'Location':'Central US','Properties':{'KeyVaultId':'/subscriptions/f073334f-240f-4261-9db5-XXXXXXXXXXXXX/resourceGroups/XXXXXXXX/providers/Microsoft.KeyVault/vaults/XXXXXXXX','KeyVaultSecretName':'XXXX-XXXXX-XXXXX','serverFarmId':'/subscriptions/f073334f-240f-4261-9db5-XXXXXXXXXXXXX/resourceGroups/XXXXXXXX/providers/Microsoft.Web/serverfarms/ServicePlan59154b1c-XXXX'}}"
When i run armclient put $putparm in the script i get this error:
"error": {
"code": "InvalidRequestContent",
"message": "The request content was invalid and could not be deserialized: 'Unterminated string. Expected delimiter: \". Path '',
line 1, position 21.'." }
But when i take the output of the $putparm variable and run the command "manually" on the server, it works.
I guess its something with the way linux store the variables and that the API is requesting JSON (or something..)
Happy for any help.
The way you define your variable putparam is wrong.
It is likely interpreted as a literal string and not as an object. Note that a simple string, like "hello", is a valid JSON data, but it probably not what is expecting your server.
If you should quote your variable correctly:
putparm="{\"Location\":\"$resolved_locationid\",\"Properties\":{\"KeyVaultId\":\"$resolved_keyvaultid\",\"KeyVaultSecretName\":\"$certname\",\"serverFarmId\":\"$resolved_farmid\"}}"
and use it like this:
armclient put "$resolved_armapi" "$putparm"

JSON get parsed in browser but not by node.js

i'm about to write some test for my client UI.
the weird thing, my JSON string:
{"match":"\s?5\.7\s?\<=\>\s?7","success":"null-coalesce-operator"}
used to be parsed by JSON.parse by browser(Chrome) and looks like this:
{
match: "\s?5\.7\s?\<=\>\s?7",
success:"null-coalesce-operator"
}
everything is fine,
but when i run that part by mocha within node.js env, i get:
{"match":"\s?5\.7\s?\<=\>\s?7","success":"null-coalesce-operator"}
^
SyntaxError: Unexpected token s
at Object.parse (native)
...
did anyone experienced stuff like this. thx for any tipp.
node version is v5.7.1
mocha version is 2.4.5
UPDATE html string that i test is:
<!doctype html><html><body><div data-meta="{"match":"\\s?5\\.7\\s?\\<=\\>\\s?7","success":"null-coalesce-operator"}"></div></body></html>
it just a single line string without any \n newlines and the same.
I think it is because it also parse specials characaters (e.g \n => line feed, \r => carriage return, etc), what chrome did not. So because you want an antislash in you regex, before parsing in node, you need to replace each\ by \\:
json_string = json_string.replace(new RegExp('\\\\', 'g'), '\\\\') //we have to use regex, because when using replace with string, it only replaces the first occurence...
otherwise, when parsing, it will tell, à \s : 'It is a special character, identified by s. But I haven't any tokens s. So I throw an error."

ExecuteScript escape quote in value

I am trying to create a local storage key/value pair. When I do:
browser.executeScript('localStorage.setItem("groups", "[test]");');
I get [test] as the value:
However, what I want it to be is ["test"]
Can someone tell me how I can modify the browser.executeScript line in order to escape double quote characters? I am running this in a protractor test.
I tried this:
browser.executeScript('localStorage.setItem("groups", "[\"test\"]");');
but get this error:
- Failed: unknown error: Runtime.evaluate threw exception: SyntaxError: missing ) after argument list
I figured it out. In case anyone else wants to know, you have to use double slash before the double quote.