So we prefer to filter for the Rule JObject and deciding then, when existing after filtering to use the retrieval for the DefaultErrorLevel
We can do also:
But when Rule JO is not present or DefaultErrorLevel is not set, then we came into a scenario that we less know what is mising the JO or the property or the value
Kindly note:
is an option to balance the scenario and the filter. We do not expect multiple rules with the same ID. So its more the case about Rule JObject found or not. Which we can handle with the FirstOrDefault
The code snippets from above can also be sliced and all parts can be used within assign statements
Also have a look on the the SelectTokens Method where we also can provide a filter in the statement
Hello, I made a script for the Invoke Code activity.
arg1 is the text of the file read with Read Text File
arg2 is the “RuleId” argument and value is the result String
Being a particular JSON file the format can be unrecognized.
So better use no encoding instead of
“typescript/text”, or “application/json”
An “UTF-8” type encoding can be used as well.
Unfortunately, reading the file from the disk is very slow.
The code for this script is the following:
Dim doc As System.Text.Json.JsonDocument
doc = System.Text.Json.JsonDocument.Parse(arg1)
Dim id As String
Dim rules As System.Text.Json.JsonElement
rules = doc.RootElement.GetProperty(“Rules”)
Dim n As Integer = rules.GetArrayLength()
For i = 0 To n -1 Step 1
id = rules.Item(i).GetProperty(“RuleId”).GetString()
If (id = arg2) Then
value = rules.Item(i).GetProperty(“DefaultErrorLevel”).GetString()
''System.Windows.Forms.MessageBox.Show(value)
End If
Next i