I want to read values of a json (message) object which has array in it.
This below query helps for immediate properties in d.
traces | extend d = parsejson(message) | d.Timestamp, d.Name;
How do I read property part of an array within d (message). For example if I want to read all street values in below message .. how to do ? This is kind of needing a loop
message
{
"Timestamp": "12-12-2008",
Name: "Alex",
address: {
[{"street": "",zip:""},{"street":"", "zip":""}]
}
}
One way to do this would be using the mvexpand operator (see documentation).
It will output a single row for each element in your array which you could iterate over.
So in your example, running:
traces | extend d = parsejson(message) | mvexpand d.address
Will output a row for each address.
Related
One of my process gives output of one csv file. I want to create an array channel from 1 to number of columns. For example:
My output
my_out_ch.view() -> test.csv
Assume, test.csv has 11 columns. Now I want to create a channel which gives me:
1,2,3,4,5,6,7,8,910,11
How could I get this? I have tried with splitText operator as below without luck:
my_out_ch.splitText(by:1,limit:1)
But it only gives me the columns names. There is a parameter elem, I am not sure if elem could give me the array and also not sure how to use it. Any help?
You could use the splitCsv operator to parse the CSV file. Then create an intRange using the map operator. Either call collect() to emit a java.util.ArrayList or call join() to emit a string. For example:
params.input_tsv = 'test.tsv'
Channel.fromPath( params.input_tsv )
| splitCsv( sep: '\t', limit: 1 )
| map { (1..it.size()).join(',') }
| view()
Results:
1,2,3,4,5,6,7,8,9,10,11
im working on a project and i have a list in kotlin like:
val list = listOf("banana", "1","apple","3","banana","2")
and i want to print it like
Output:
banana = 1
banana = 2
apple = 3
so like every work with the number should be like one val, and i need to print in scific order (the order is toooo random for any sort command), so im panning on just coppying the whole xinhua dictionary here (since all chinese words have a scific unicode), and make the code it replace like:
val list = listOf("banana丨", "1","apple丩","3","banana丨","2")
but how to print them in the order?
ps. even me as a chinese dont know most of the words in xinhua dictionary lol so there is more then enofe
Assuming that you have the following input list, as shown in your question, where the order of occurrence is always one word followed by the scific order:
val list = listOf("banana", "1","apple","3","banana","2")
You could do the following:
1. Create a data class that defines one entry in your raw input list
data class WordEntry(val word: String, val order: Int)
2. Map over your raw input list by using the windowed and map methods
val dictionary = list.windowed(2, 2).map { WordEntry(it.first(), it.last().toInt()) }
Here, the windowed(2, 2) method creates a window of size 2 and step 2, meaning that we iterate over the raw input list and always work with two entries at every second step. Assuming that the order in the raw input list is always the word followed by the scific order, this should work. Otherwise, this would not work, so the order is very important here!
3. Sort the transformed dictionary by the order property
val sortedDictionary = dictionary.sortedBy { it.order }
Edit: You can also sort by any other property. Just pass another property to the lambda expression of sortedBy (e.g. sortedBy { it.word } if you want to sort it by the word property)
4. Finally, you can print out your sorted dictionary
val outputStr = sortedDictionary.joinToString("\n") { "${it.word} = ${it.order}" }
print(outputStr)
Output:
banana = 1
banana = 2
apple = 3
I want to count the number of occurrence of a specific JSON structure. For example in my event there is a field called data which its value is JSON . but this field can have a variety of structures. like:
data = {a: "b"}
data= {d: "x", h: "e"}
...
now I want to know how many event has data with each JSON structure and I don't care about values only keys are matter.
Try one of these 2:
index=ndx sourcetype=srctp data=*
| stats dc(data) as unique_data
Or
index=ndx sourcetype=srctp data=*
| stats values(data) as data_vals
Desciption:
I have an array 2d:
$array = InvApplication::model()->findall(array('order'=>'app_name'));
The array contents the next element: "app5", How to avoid it?
Actual Output:
app_name|field1|field2|fieldN|..|..
appn |
appn1 |
appn2 |
app5 |
Already Tested
I have been testing with unset, in_array and strpos functions.
In addition to:
php - finding keys in an array that match a pattern
Delete element from multidimensional-array based on value
My actual piece of code:
This is an actual way, but is not working as I want.
$deleteapp = "app5";
unset($list[$deleteapp]); Test with unset or array_diff
foreach($list as $k=>$v)
{
if(in_array($v,array('app5'))) unset($list[$k]);}
I expect this:
app_name|field1|field2|fieldN|..|..
appn |
appn1 |
appn2 |
Thank you.
seems you want exclude a app_name from the select result
in this case you could use a condition
$array = InvApplication::model()->findall(
array("condition"=> "app_name != 'app5'","order"=>"app_name")
);
I'd like to know if it's possible, on Selenium IDE, to check the first letter of value inside a variable. For example, I have a variable called cartId, and this variable stores IDs inside it. Sometimes, the ID starts with "A", "E" or "P", examples:
A324FR
E289FS
P23U87
So i'd like to make something like this:
If starts with A, stores "A" in an auxiliary variable.
If starts with E, stores "E" in an auxiliary variable.
If starts with P, stores "P" in an auxiliary variable.
This is needed because depending on the first letter of the value, it will do a different method ... so I can use something like (command, target, value):
gotoIf | ${auxiliaryVariable} == 'A' | METHOD1
gotoIf | ${auxiliaryVariable} == 'E' | METHOD2
gotoIf | ${auxiliaryVariable} == 'P' | METHOD3
Thanks!
You could probably use storeEval to evaluate JavaScript to get your auxiliaryVariable
storeEval | document.getElementById("cartId").textContent[0] | auxiliaryVariable
This will get the element regardless of the text, then store the first letter A, E, or P inside of auxiliaryVariable for use later.
Thanks for all the help, I could do it using:
store | javascript{storedVars['cartId'].substring(0,1);} | auxiliary