I have a WebHook activity in Azure Data Factory pipeline but I'm not able to pass variables here.
#json('{
"body": "#{pipeline().parameters.body}",
"name": "#{variables('name')}"
}')
There is a problem with '. I've tried with \'name\' but it does not work.
The body representing the payload to be be sent to endpoint must be Valid JSON or an expression that results a value of type JSON. So in WebHook activity you can just pass the JSON string rather than using the function json() again.
Checkout this example:
Use any string variable:
Using the variable and parameter in JSON string:
{
"var":"#{variables('variable')}",
"param":"#{pipeline().parameters.parameter}",
"age":"23"
}
by string interpolation, the value of variable is replaced in place
Related
POST API is triggering fine and taking only first json object from array and rest of the json objects are not passing. I need to trigger API with multiple json payloads sequentially using JMeter and Groovy.
json payload : Below is the sample json payload
[
{
"person": "abc",
"Id": "123"},
{
"person": "adfg",
"Id": "12883"},
{
"person": "adf",
"Id": "125"}
]
Groovy code : Reading data from json file which includes multiple json objects and send it to post request in jmeter.
try
{
JsonSlurper jsonSlurper=new JsonSlurper();
def jsonPayload = jsonSlurper.parse(new File('PAYLOAD.json'))
String inputData = new groovy.json.JsonBuilder(jsonPayload)
JsonElement root = new JsonParser().parse(inputData);
JsonArray jsonArray = root.getAsJsonArray();
log.info("jsonArray:"+jsonArray);
if(jsonArray != null && !jsonArray.isEmpty())
{
jsonArray.each{paylodData ->
println paylodData
log.info("post data:"+paylodData);
vars.putObject("payloads", paylodData.toString())
log.info('Generated body: ' + vars.getObject('payloads'))
}
}
}catch (FileNotFoundException fe) {
log.info("Error: Please Check the file path");
}
JMeter Test : Triggering same API with multiple payloads
using below variable in post request body
${payloads}
NOTE : API is triggering fine and taking only first json object and rest of the json objects are not passing. I need to trigger API with multiple json payloads sequentially.
What are you trying to achieve?
You have a foreach loop which iterates the JSON Array and writes the inner object value into a payloads JMeter Variable
The point is that each iteration of the foreach loop overwrites the previous value in the variable so you will always get the last value.
You either need to replace jsonArray.each with jsonArray.eachWithIndex and store each array member into a separate variable like:
payload_0 = first array member
payload_1 = second array member
etc.
or transform the response into another format, but here I cannot suggest anything because I don't know what is the expected one.
More information:
Apache Groovy - Parsing and producing JSON
Apache Groovy: What Is Groovy Used For?
How can i pass a JSON string in the JSON body of the HTTP request? The request is sent by ServiceNow to Azure Devops to set the content of a pipeline variable.
The Json body is as below:
{
"resources":{
"repositories":{
"self":{
"refName":"refs/heads/master"
}
}
},
"variables":{
"request":{
"value":"{"key1": "value1"}" #here, i declare the json string
}
}
}
"{"key1": "value1"}" is the json string that i want to pass (this is just a sample of the string).
I have tried backslash '' in front of the braces. "\{"key1": "value1"\}" It didn't work.
I have tried to put the braces between single or double quotations. "'{'"key1": "value1"'}'" It didn't work.
Do you have any idea? Maybe it is doable with the ServiceNow's language but i am not expert of it. As Azure Devops only accepts strings as pipeline variables, i have to send the json as a string.
You have to escape the double quotes of the value:
{\"key1\": \"value1\"}
I have an object array like below
[ {"name":"heamoglobin","reading":"12"},
{"name":"mrc","reading":"3.3"},
{"name":"hct","reading":"33"} ]
I need to send this as an argument for my chaincode function. I tried stringifying the whole array
like this
"[{\"name\":\"heamoglobin\",\"reading\":\"12\"},{\"name\":\"mrc\",\"reading\":\"3.3\"},{\"name\":\"hct\",\"reading\":\"33\"}]"
but didnt get a successful transaction
Any suggestions?
You must convert to string each parameter that is not already string. Something like:
await contract.submitTransaction("createReport", uid, req.body.patientID, user[0].email, clinicProfile.centerName, date.toString(), JSON.stringify(data));
And then process suitably every parameter in your chaincode's operation (unmarshal the array, etc.).
Passing a valid JSON Message to the #xml() function works but the output seems to be somehow serialized. Is there a reference how to use the #xml() function or does anybody know what i'm doing wrong?
Expression in Data Operations - Compose Function (where 'Add_Root_Element' is the previous Function Block):
"inputs": {
"xml": "#xml(outputs('Add_Root_Element'))"
}
Generated Output:
{
"xml": {
"$content-type": "application/xml;charset=utf-8",
"$content": "PHJvb3Q+PHBhcnRpY2lwYW50Pjxjb3VudHJ5PkF1c3RyYWxpYTwvY291bnRyeT48ZGVwYXJ0bWVudD5JbmZvcm1hdGlvbiBUZWN...
}
}
This question relates to the following question: Azure Logic App - JSON to XML Conversion
The xml function returns a Base 64 string, if you take that $content value and transforms from Base 64 to string, you will obtain the generated XML.
A simple proof of concept is generate an HTTP Request - Response Logic App, that receives a JSON and in the output you assign to de body #xml(triggerBody()).
When you call, you will see in the output the XML representation of your input.
I want to write an API ReST endpoint, using Spring 4.0 and Groovy, such that the #RequestBody parameter can be any generic JSON input, and it will be mapped to a Groovy JsonSlurper so that I can simply access the data via the slurper.
The benefit here being that I can send various JSON documents to my endpoint without having to define a DTO object for every format that I might send.
Currently my method looks like this (and works):
#RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<String> putTest(#RequestBody ExampleDTO dto) {
def json = new groovy.json.JsonBuilder()
json(
id: dto.id,
name: dto.name
);
return new ResponseEntity(json.content, HttpStatus.OK);
}
But what I want, is to get rid of the "ExampleDTO" object, and just have any JSON that is passed in get mapped straight into a JsonSlurper, or something that I can input into a JsonSlurper, so that I can access the fields of the input object like so:
def json = new JsonSlurper().parseText(input);
String exampleName = json.name;
I initially thought I could just accept a String instead of ExampleDTO, and then slurp the String, but then I have been running into a plethora of issues in my AngularJS client, trying to send my JSON objects as strings to the API endpoint. I'm met with an annoying need to escape all of the double quotes and surround the entire JSON string with double quotes. Then I run into issues if any of my data has quotes or various special characters in it. It just doesn't seem like a clean or reliable solution.
I open to anything that will cleanly translate my AngularJS JSON objects into valid Strings, or anything I can do in the ReST method that will allow JSON input without mapping it to a specific object.
Thanks in advance!
Tonya