I have a json response with a list of strings. I want to check if it contains the same elements as some other list (order of those elements isn't important. How do I do that?
I tried this:
jsonPath("$.country_codes[*]").findAll.sorted.is(List("DE", "CH", "FR", "IE", "IT", "NL", "RS", "UK", "IN").sorted)
but I'm getting error "Cannot resolve symbol sorted". If I don't use 'sorted', it works, but I can't rely on getting the same order of elements from server each time..
Use transform to turn your Seq[String] into a Set[String] or sort it.
Related
lets say I have 2 lists:
listOfCountries = List("United States", "Belgium", "Germany")
SecondlistOfCountries = List("Italy", "France", "Germany")
oneOf:
I want to check if there is at least one item that appears in both lists (the example will be "true")
Contains:
I want to check if one of the items in the SecondlistOfCountries list contains one of the items in the listOfCountries list (as a substring)
how would you do something like this in a clean Scala way?
thanks
oneOf can be also written as:
listOfCountries.exists(SecondlistOfCountries.contains)
For contains I suggest the same as #Tim.
oneOf:
listOfCountries.exists(SecondlistOfCountries.contains)
[ Thanks to #Ava for this version, which is much better than my original solution ]
contains:
SecondlistOfCountries.exists(c => listOfCountries.exists(c.contains))
I am trying to use a Lookup Activity to return a row count. I am able to do this, but once I do, I would like to run an If Statement against it and if the count returns more than 20MIL in rows, I want to execute an additional pipeline for further table manipulation. The issue, however, is that I can not compare the returned value to a static integer. Below is the current Dynamic Expression I have for this If Statement:
#greater(int(activity('COUNT_RL_WK_GRBY_LOOKUP').output),20000000)
and when fired, the following error is returned:
{
"errorCode": "InvalidTemplate",
"message": "The function 'int' was invoked with a parameter that is not valid. The value cannot be converted to the target type",
"failureType": "UserError",
"target": "If Condition1",
"details": ""
}
Is it possible to convert this returned value to an integer in order to make the comparison? If not, is there a possible work around in order to achieve my desired result?
Looks like the issue is with your dynamic expression. Please correct your dynamic expression similar to below and retry.
If firstRowOnly is set to true : #greater(int(activity('COUNT_RL_WK_GRBY_LOOKUP').output.firstRow.propertyname),20000000)
If firstRowOnly is set to false : #greater(int(activity('COUNT_RL_WK_GRBY_LOOKUP').output.value[zero based index].propertyname),20000000)
The lookup result is returned in the output section of the activity run result.
When firstRowOnly is set to true (default), the output format is as shown in the following code. The lookup result is under a fixed firstRow key. To use the result in subsequent activity, use the pattern of #{activity('MyLookupActivity').output.firstRow.TableName}.
Sample Output JSON code is as follows:
{
"firstRow":
{
"Id": "1",
"TableName" : "Table1"
}
}
When firstRowOnly is set to false, the output format is as shown in the following code. A count field indicates how many records are returned. Detailed values are displayed under a fixed value array. In such a case, the Lookup activity is followed by a Foreach activity. You pass the value array to the ForEach activity items field by using the pattern of #activity('MyLookupActivity').output.value. To access elements in the value array, use the following syntax: #{activity('lookupActivity').output.value[zero based index].propertyname}. An example is #{activity('lookupActivity').output.value[0].tablename}.
Sample Output JSON Code is as follows:
{
"count": "2",
"value": [
{
"Id": "1",
"TableName" : "Table1"
},
{
"Id": "2",
"TableName" : "Table2"
}
]
}
Hope this helps.
Do this - when you run the debugger look at the output from your lookup. It will give a json string including the alias for the result of your query. If it's not firstrow set then you get a table. But for first you'll get output then firstRow and then your alias. So that's what you specify.
For example...if you put alias of your count as Row_Cnt then...
#greater(activity('COUNT_RL_WK_GRBY_LOOKUP').output.firstRow.Row_Cnt,20000000)
You don't need the int function. You were trying to do that (just like I was!) because it was complaining about datatype. That's because you were returning a bunch of json text as the output instead of the value you were after. Totally makes sense after you realize how it works. But it is NOT intuitively obvious because it's coming back with data but its string stuff from json, not the value you're after. And functions like equals are just happy with that. It's not until you try to do something like greater where it looks for numeric value that it chokes.
I use RestHeart to get data from MongoDB. When I request a document from a collection that contains a field of type int64 (in this example "INT64_NUMBER") the response contains:
"FLAG_A": "Y",
"FLAG_B": "N",
"INT64_NUMBER" {
"$numberLong": "34"
},
"NUM_D": 123
Is there any option to obtain the same information without the type "$numberLong"? I mean, something like the following:
"FLAG_A": "Y",
"FLAG_B": "N",
"INT64_NUMBER": "34",
"NUM_D": 123
I thought that I should use some kind of aggregation with a project but I can't find a solution by myself neither an example on the web. Does anybody can guide me to find a proper solution? Thanks in advance.
No, you can't. That's the strict json representation of bson https://docs.mongodb.com/manual/reference/mongodb-extended-json/
I have array which I need to parse into Talent
{
"sEcho": 1,
"iTotalRecords": 54,
"iTotalDisplayRecords": 54,
"aaData": [
[
"79",
"testowy2",
"testowy samochod",
"12.00",
"14.00",
"2147483647",
"posciel",
""
]
]
}
What would be Xpath Query which I need to pass on the tExtractJSONFields ?
you might use JSONPath query to read the multi dimensional array via tExtractJSONFields.
For query building (with respect to above data), please refer below screen shot :
you will get the array in "id" field.
Let me know if you face any problem.
It is not possible to do this,
"Please check right XPathExpression or XML source document." error is occuring...
Your input is a valid json but not a valid XML Document
I currently have an ordered JSON string being passed into my iPhone app, which is then being parsed using the JSON Framework.
The data is as follows:
"league_table": object{
"Premiership": array[6],
"Championship": array[6],
"Division 1": array[6],
"Division 2": array[6],
"Division 3": array[6]
}
However when it parses that, it throws out a weird order.
Division 2
Division 1
Championship
"Division 3"
Premiership
Which I got by calling : NSLog(#"%#",[dictionaryValue allKeys]);.
Has anyone experienced this before? Any idea what to do to sort it again?
UPDATE ::
The shortened UN-Parsed JSON is here :
{"league_table":
{
"Premiership":[],
"Championship":[],
"Division 1":[],
"Division 2":[],
"Division 3":[]}
}
As far as I can tell, this is a Key/Value Pair, so it should be parsed in the same order.
For instance going to http://json.parser.online.fr/ and pasting that in will parse it in the correct order.
However the JSON-Framework doesn't parse it the same, it parses it in a strange order with no real sorting going on
JSON object fields don't have a defined order. If you want key/value pairs in a defined order, there are basically two options:
An array of single-field objects:
[{"Premiership": array[6]},
{"Championship": array[6]},
{"Division 1": array[6]},
{"Division 2": array[6]},
{"Division 3": array[6]}]
An array of key/value pairs:
[["Premiership", array[6]],
["Championship", array[6]],
["Division 1", array[6]],
["Division 2", array[6]],
["Division 3", array[6]]]
Sidenote: I'm half-guessing that the relationship between the sample data and JSON. I don't know what object and array[6] are doing there.
Yep, I've seen that before.
Does this cause you a problem? it looks like a Dictionary (keyed) .. so I guess your application just accesses the required elements by it's key.
I believe a JSON array format would maintain the order.
EDIT
Ok, so you need to maintain the order ... but from what you say, it looks like the key isn't important.
Are you in control of the creation of the JSON string ? If so, could you present the data like this :
[
{
"leagueName":"Premiership",
"leagueLines":[...]
},
{
"leagueName":"Championship",
"leagueLines":[...]
},
{
"leagueName":"League One",
"leagueLines":[]
},
... etc ....
]
I've put in the leagueName in just for information ... who know's you might need it for something :)
Good Luck