Azure ADF - Array elements can only be selected using an integer index - json

Hi I am trying to select Status from Json Array in azure data factory
{
"dataRead": 2997,
"dataWritten": 2714,
"filesWritten": 1,
"sourcePeakConnections": 1,
"sinkPeakConnections": 1,
"rowsRead": 11,
"rowsCopied": 11,
"copyDuration": 3,
"throughput": 0.976,
"errors": [],
"effectiveIntegrationRuntime": "DefaultIntegrationRuntime (East US)",
"usedDataIntegrationUnits": 4,
"billingReference": {
"activityType": "DataMovement",
"billableDuration": [
{
"meterType": "AzureIR",
"duration": 0.06666666666666667,
"unit": "DIUHours"
}
]
},
"usedParallelCopies": 1,
"executionDetails": [
{
"source": {
"type": "AzureSqlDatabase",
"region": "East US"
},
"sink": {
"type": "AzureBlobStorage",
"region": "East US"
},
"status": "Succeeded",
"start": "2020-03-19T06:24:39.0666585Z",
"duration": 3,
"usedDataIntegrationUnits": 4,
"usedParallelCopies": 1,
I have tried selecting #activity('Copy data From CCP TO Blob').output.executionDetails.status.It throws an error:
'Array elements can only be selected using an integer index'.
Any way to resolve it?

executionDetails is an array, you have to set index to refer elements in it.
Please try:
#activity('Copy data From CCP TO Blob').output.executionDetails[0].status

Thank you for the reply
Yes, we have to use slicing and indexing the lists and Dictionaries
I have tried Dispensing_Unit_Master_Dim
#activity('Copy data From CCP TO Blob').output.executionDetails[0]['status'] and it works
0 and status there is no Dot

Related

Gpath for JSON with nested findAll

I have the following response payload
[{
"id": 1,
"catname": "Cat01",
"items": [{
"Name": "Item01",
"id": 2
}, {
"Name": "Item02",
"id": 3
}]
},
{
"id": 4,
"catname": "Cat02",
"items": [{
"Name": "Item03",
"id": 5
}, {
"Name": "Item04",
"id": 6
}]
},
{
"id": 7,
"catname": "Cat03",
"items": [{
"Name": "Item05",
"id": 8
}]
}
]
I want to retrieve a list of all the items.ids (but not the ids of their parents), So this: [2, 3, 5, 6, 8].
I've tried this findAll{it}.items.findAll{it}.id but it doesn't work. Any help would be welcomed. Thanks!
You don't need to use findAll here to iterate, and you can make use of collectMany to automatically flatten the list
Assuming your parsed json is in a variable json, you can simply do:
json.items.collectMany { it.id }
Never mind, I found the answer :).
I needed to use flatten here
items.flatten().id
did the trick.
I got the answer from here: How to search in anonymous and nested array using find or findAll in groovy's closures using REST-Assured library?

Jsonpath - Accessing array item using expression

I am using AWS Step Functions which utilizes JSONPath for providing JSON paths. I have the following input :
{
"response": {
"isSuccess": true,
"error": "",
"body": {
"count": 2,
"fields": [
{
"fieldId": 1,
"tabId": 100,
"title": "First Name"
},
{
"fieldId": 2,
"tabId": 100,
"title": "Last Name"
}
]
}
},
"iteration": {
"totalCount": 2,
"currentCount": 0,
"step": 1
}
}
I want to query the fields array as:
$.response.body.fields[$.iteration.currentCount]
The value of currentCount is incremented by 1 as part of an iteration.
I am getting an invalid XPath exception when trying to use the above.
Can someone please advice on how to provide a dynamic property value to read array values?
As described on https://github.com/json-path/JsonPath#operators you can index an array with a number only. However, you can use a filter expression to select a specific item from the array as follows.
Assuming you have another field that denotes the index such as:
{
"index": 0,
"fieldId": 2,
"tabId": 100,
"title": "Last Name"
}
You can then do
$.response.body.fields[?(#.index==$.iteration.currentCount)]

Remove pivote attribute from JSON response in Laravel 5.2

I'm using many to many relationships using pivot table. But the problem is when I'm returning json response, the json also contains the pivot attribute as shown below:
{
"id": 2,
"job_title": "et",
"job_description": "Iusto provident.",
"job_industry": "Braun, Jast and Quigley",
"job_location": "Christiansenland",
"job_experience": 7,
"employment_type": "full",
"recruiter_id": 9,
"status": 1,
"posted_date": "2016-02-02 07:55:28",
"skills": [
{
"id": 1,
"value": "molestiae",
"pivot": {
"job_id": 2,
"skill_id": 1
}
}
]
}
What I want is something like this:
{
"id": 2,
"job_title": "et",
"job_description": "Iusto provident.",
"job_industry": "Braun, Jast and Quigley",
"job_location": "Christiansenland",
"job_experience": 7,
"employment_type": "full",
"recruiter_id": 9,
"status": 1,
"posted_date": "2016-02-02 07:55:28",
"skills": [
{
"id": 1,
"value": "molestiae",
}
]
}
I have tried various solutions from the stackoverflow questions, but none of them seem to work. I'm new to Laravel. If you guys need more info on the model,I can post it. Please help.
Go to your Skill model and set:
protected $visible = ['id', 'value'];

VB.Net Select Nested Json With Same Name

example json (snippet taken from a valid json
"items": {
"average": 564,
"head": {
"id": 99161,
i already know how to display and select values from this i currently use
average.text = If(jResults("average") Is Nothing, "", jResults("average").ToString())
id.text =If(jResults("items")("head") Is Nothing, "", jResults("items")("head")("id").ToString())
however i am unsure how to extract the stat values from the following snippet as stat is used multiple times
"items": {
"averageItemLevel": 564,
"averageItemLevelEquipped": 564,
"head": {
"id": 99161,
"stats": [
{
"stat": 32,
"amount": 651,
"reforgedAmount": -434
},
{
"stat": 5,
"amount": 2001
},
{
"stat": 36,
"amount": 1544
},
{
"stat": 7,
"amount": 3362
},
{
"stat": 49,
"amount": 434,
"reforged": true
}
],
"armor": 2244
},
im unsure how to extract each stat and place it in a different box using the string i used before
average.text = If(jResults("average") Is Nothing, "", jResults("average").ToString())
i understand i may have to use select case but im not sure how to use my existing string to determine each stat
thanks
Looks like you'd have to use an array index on "stats", so that in your example JSON, you could get the first two values using
jResults("items")("head")("stats")(0)("stat").ToString() ' = "32"
and
jResults("items")("head")("stats")(1)("stat").ToString() ' = "5"
So if for instance you wanted to total all of the "stat" fields, you could do it like so:
Dim statTotal As Integer = 0
For i As Integer = 0 To jResults("items")("head")("stats").Count - 1
statTotal += CInt(jResults("items")("head")("stats")(i)("stat"))
Next
(Of course, in the real world you'd check to make sure each one is not Nothing and that IsNumeric() is true before just throwing a CInt() in there.)
Hope that helps!

JSON contains minus ("-") char: is this valid/standard?

I'm working with an API that is sending JSON responses like this:
[
- {
"id": 46843639,
"nickname": "JSON",
"registration_date": "2004-03-07T23:16:20.000-04:00",
"country_id": "BR",
"user_type": "normal",
"logo": null,
"points": 91,
"site_id": "JSN",
"permalink": "http://xxxxxx",
"seller_reputation": - {
"level_id": "2_orange",
"power_seller_status": null,
"transactions": - {
"period": "historic",
"total": 14,
"completed": 8,
"canceled": 6,
"ratings": - {
"positive": 1,
"negative": 0,
"neutral": 0,
},
},
},
"status": - {
"site_status": "active",
},
},
]
I couldn't find that minus '-' sign in any specification documents. Is this JSON standard?
No, it's not. The server is sending you broken JSON.
The only times - is valid are when it's in a string, when it immediately precedes a number, or when it immediately follows the e or E in a floating-point number.
Add to that, commas should separate name/value pairs and array elements, not follow them. Those commas following the last entry in each object / array, are invalid as well.