i have a response after a request with soapui.
in the response i have several element with the same name for example ID
The content of ID is different at many places.
here is the response:
{
"assig":[
{
"id":1,
"repId":2,
"enTId":3,
"Type":"Report",
"recipients":[]},
{
"id":2,
"repId":3,
"enTId":4,
"Type":"Report",
"recipients":[]}
When i try this:
testRunner.testCase.testSuite.setPropertyValue('id',slurperresponse.id.toString() )
It sets in property all ID in one line separated by comma like this: [1,2]
How can i separate them in different name in property?
Thank you
You're converting a list to a string
Try
slurperresponse.id.eachWithIndex { id, idx ->
testRunner.testCase.testSuite.setPropertyValue("id${idx+1}", "$id") // or id?.toString()
}
Related
How do you get NLog to format data as JSON when using ILogger.BeginScope? It appears the the # symbol is ignored, or just not coded to work with begin scope? ref documentation
I've tried every combination I can think of and they all result in the object being ToString'd rather than converted to JSON. The end result is that the data is not searchable as "structured" data because it's just a string.
1st Attempt:
using (_logger.BeginScope(new Dictionary<string, object>
{
["CacheValue"] = value
}))
{
_logger.LogInfo("howdy");
}
Result in Seq:
howdy
CacheValue MyApp.ViewModels.EntityIssueQueueGetModel
2nd Attempt:
using (_logger.BeginScope(new Dictionary<string, object>
{
["#CacheValue"] = value
}))
{
_logger.LogInfo("howdy");
}
Result in Seq:
howdy
#CacheValue MyApp.ViewModels.EntityIssueQueueGetModel
3rd Attempt:
using (_logger.BeginScope(new Dictionary<string, object>
{
["{#CacheValue}"] = value
}))
{
_logger.LogInfo("howdy");
}
Result in Seq:
howdy
{#CacheValue} MyApp.ViewModels.EntityIssueQueueGetModel
4th Attempt:
using (_logger.BeginScope("{#CacheValue}", value))
{
_logger.LogInfo("howdy");
}
Result in Seq:
howdy
#CacheValue MyApp.ViewModels.EntityIssueQueueGetModel
This next bit works, but is not what I need. This prints the JSON out along with the friendly message. I only want the JSON data to be associated with the log for querying purposes; not shown as part of the message.
Working example:
_logger.LogInfo("howdy. {#CacheValue}", value);
Result in Seq:
howdy. {"Issues":[],"TotalRecords":0,"Success":true,"TraceId":"00-3b8ef0c2d84714e0c81a07cbb5d50444-8269922e21923478-00","Errors":[]}
CacheValue {
"Issues": [],
"TotalRecords": 0,
"Success": true,
"TraceId": "00-3b8ef0c2d84714e0c81a07cbb5d50444-8269922e21923478-00",
"Errors": []
}
NLog doesn't recognize message-template-syntax for Scope-Context-Properties.
NLog JsonLayout can format Scope-context Properties like this:
<layout xsi:type="JsonLayout" includeScopeProperties="true" maxRecursionLimit="1">
</layout>
See also: https://github.com/NLog/NLog/wiki/JsonLayout
It is also possible to format a single Scope-context Property as Json like this:
layout="${scopeproperty:CacheValue:format=#}"
See also: https://github.com/NLog/NLog/wiki/ScopeProperty-Layout-Renderer
It is also possible to format the entire Scope-Nested-Stack as Json like this:
layout="${scopenested:format=#}"
See also: https://github.com/NLog/NLog/wiki/ScopeNested-Layout-Renderer
Maybe consider posting your question at https://github.com/datalust/nlog-targets-seq
I am working with Firebase and Python, but I have a small error when I try to add this data to a specific user and it is generating the following error, thanks I hope you help me
TypeError: put () got multiple values for argument 'connection'
def Newcompra(user,items):
global PlayerDB,TiendaDB
info = {
"id": TiendaDB[items]["id"],
"nombre": TiendaDB[items]["nombre"],
"historia": TiendaDB[items]["historia"],
"tipo": TiendaDB[items]["tipo"],
"g_type": TiendaDB[items]["g_type"],
"peso": TiendaDB[items]["peso"],
"tier": TiendaDB[items]["tier"],
"envolver": TiendaDB[items]["envolver"],
"evento_item": TiendaDB[items]["evento_item"],
"fabricable": TiendaDB[items]["fabricable"],
"intercanbio": TiendaDB[items]["intercanbio"],
"precio": TiendaDB[items]["precio"],
"venta": TiendaDB[items]["venta"],
"atributos": {
"ataque": TiendaDB[items]["atributos"]["ataque"],
"defensa": TiendaDB[items]["atributos"]["defensa"],
"mana": TiendaDB[items]["atributos"]["mana"],
"habilidad": TiendaDB[items]["atributos"]["habilidad"],
"nivel": TiendaDB[items]["atributos"]["nivel"]
}
}
Fire.put("/players",user,"/bolso_arm",items,info)
return```
I think you are sending too many parameters to Fire.put
It is expecting:
(url, name, data, params, headers, connection)
In normal use, you will only want to use the first three parameters. I am guessing your variables user and items each contain a string. It looks to me that you are trying to write, to a path such as:
/players/some-user-name/bolso_arm
the following information:
{
"some-key": info
}
I think you are aiming to achieve this database entry on Firebase:
/players/some-user-name/bolso_arm/some-key: {
"id": "......",
"nombre": "......",
"historia": "......",
....
}
You should merge all the elements of the path, except the last one, into a single string for the first parameter
I think you want the first parameter, path, to be:
/players/some-user-name/bolso_arm/
Then the second, name, to be:
some-key
And finally the data to be:
{
"id": "......",
"nombre": "......",
"historia": "......",
....
}
Proposed code
I have added a "/" after "players".
Fire.put("/players/"+user+"/bolso_arm",items,info)
Now there are only three parameters, and it should work. Let us know how you get on.
Terraform Version 0.14
I have a JSON file that has multiple objects. I get that file using the local_file data source.
data "local_file" "getJson" {
filename = "${path.module}/sampleObject.json"
}
sampleObject.json:
{
"config":[
{
"id":1,
"type":"typeA",
"vm_name":"Linux1"
},
{
"id":2,
"type":"typeB",
"vm_name":"Windows1"
},
{
"id":3,
"type":"typeB",
"vm_name":"Windows2"
}
]
}
I use a local variable to save and convert the contents of my JSON file to a usable Terraform objects with the jsondecode function. I believe the jsondecode function is converting my JSON object to a map ( I could be wrong). One of the attributes of my JSON object(s) is type. There are two possible values for type (typeA & typeB). I need a way to select all the objects in my JSON object that match a specific type (ie: type == "typeA"). The roadblock for me has been making sure the new collection is either a map or another collection that can be converted to a map using the tomap() function.
My sample code below does exactly what I need it to do using a for loop except... it saves it as a Tuple. In the For loop documentation, there is alternative to save it to an object using {} but I haven't been able to figure out how that works in my given example.
I've reached a point where I think I'm going about the problem wrong with using a for loop. I could use some advise on this. I also think If I can get the for loop to work using {} so the results are saved as an object, I should be able to convert that object to a map using the tomap() function without any issues.
I'm still new to Terraform and any guidance would be appreciated.
For loop reference
locals {
typeA = [ for x in jsondecode(data.local_file.getJson.content).config : x if x.type == "typeA" ]
typeB = [for x in jsondecode(data.local_file.getJson.content).config : x if x.type == "typeB"]
}
This is a redacted sample of how I would use the results.
module "typeABuilder" {
for_each = local.typeA
vm_name = each.value.vm_name
// Assign each attribute from the typeA objects
// ...
// ...
}
module "typeBBuilder" {
for_each = local.typeB
vm_name = each.value.vm_name
// Assign each attribute from the typeB objects
// ...
// ...
}
I am testing RESTful webservice using SoapUI. We use Groovy for that.
I am using jsonslurper to parse the response as Object type.
Our reponse is similar to this:
{
"language":[
{
"result":"PASS",
"name":"ENGLISH",
"fromAndToDate":null
},
{
"result":"FAIL",
"name":"MATHS",
"fromAndToDate": {
"from":"02/09/2016",
"end":"02/09/2016"
}
},
{
"result":"PASS",
"name":"PHYSICS",
"fromAndToDate":null
}
]
}
After this, I stuck up on how to.
Get Array (because this is array (starts with -language)
How to get value from this each array cell by passing the key (I should get the value of result key, if name='MATHS' only.)
I could do it using Java, but as just now learning Groovy I could not understand this. We have different keys with same names.
You can just parse it in to a map, then use standard groovy functions:
def response = '''{
"language":[
{"result":"PASS","name":"ENGLISH","fromAndToDate":null},
{"result":"FAIL","name":"MATHS","fromAndToDate":{"from":"02/09/2016","end":"02/09/2016"}},
{"result":"PASS","name":"PHYSICS","fromAndToDate":null}
]
}'''
import groovy.json.*
// Parse the Json string
def parsed = new JsonSlurper().parseText(response)
// Get the value of "languages" (the list of results)
def listOfCourses = parsed.language
// For this list of results, find the one where name equals 'MATHS'
def maths = listOfCourses.find { it.name == 'MATHS' }
How can we capture only the email address in an api response for the gmail API. The
fields parameter is set to payload/headers, which returns way more data than we need in the response.
All we need is the value from one name/value pair in the JSON response; for example
The full response as we have it now looks something like this
{
"payload": {
"headers": [
{
"name": "Delivered-To",
"value": "xxxxxxx"
{
"name": "Received",
"value": "xxxxxxxx"
},
{
"name": "Received-SPF",
"value": "----"
},......
{
"name": "To",
"value": "xxxxxxx"
}, ...... E.T.C........E.T.C ......
/*All we want is one name/value pair to be returned e.g. */
{
"payload": {
"headers": [
{
"name": "X-Failed-Recipients",
"value": "............."
}
]
}
A better question might be is there a better way to capture bounced/returned mail than this via the gmail API?
Also, is it possible to request an XML response instead of JSON. How can that be done for the gmail API?
Thanks !!
You can do messages.get(format=METADATA, metadataIncludeHeaders=["To", "From", "Subject"]) for example, now to just request the specific headers you care about . Note this only works with the metadata format (it won't include the body also, if you want all the body you get the full email. Based on the list of headers, shouldn't be too hard to turn that into a map/dict of key => [list, of, values].
As to your second question, yes you can definitely request response in any format you want. That's a standard Google API question though. I can't find a good reference (surely some searching will) but typically you can set an "alt=xml" or "alt=" query parameter to get response in that format. Not sure how this is exposed in any particular client library.
First you need to get your message payload and then you want to use the getall method to return a list of headers and then you can use the getitem to pull any specific header you want from that list.
I converted the String into a String and took it as a JSON Array and iterated through it to take the JSON Object that I required.
private static DirtyMail getHeaderParts(DirtyMail mail, List<MessagePartHeader> headers)
{
try {
//Convert the header into JSON Array for easy processing of data.
JSONArray headerArray = new JSONArray(headers.toString());
for(int n = 0; n < headerArray.length() ; n++) {
JSONObject jsonObject = headerArray.getJSONObject(n);
//Pull date
if(jsonObject.get(Constants.DATE)!=null) {
mail.setDate(jsonObject.getString(Constants.DATE));
}
//Pull Subject
//Pull reply-to address
//Pull delivered-from address
//Pull delivered-to address
Log.d(TAG, "JSON Object : "+ jsonObject);
}
//Log.d(TAG,"header String: "+headers.toString());
} catch (Exception e) {
e.printStackTrace();
}
return mail;
}
I kept these values in the Constant class :
// Data pulled from inside the header
public static final String DATE = "Date";
public static final String SUBJECT = "Subject";
public static final String REPLY_TO = "Reply-To";
public static final String DELIVERED_TO = "Delivered-To";
public static final String FROM = "From";
I don't know if this is the best fix for this, but this works and gives the data as I require.