Microsoft flow return JSON wrong format - power-automate

Currently I have this:
Which is the output I want so just 1 as output
But the next step is parse JSON which results in this output:
How can I make that the parse JSON also returns 1 as output without the rest of the text?

In the step after "Parse JSON", you'll be able to select "id" in your "Dynamic content" and that will be just "1"

Related

Jmeter - Extracting a a JSON value by validating with another value

It is possible to get a JSON value by validating with another value.
For example i am getting multiple responses as below;
{
"place_name": "Home",
"selected_icon": "http:\/\/abc.tech\/images\/home_selected.png",
"updated_at": "2017-11-10 12:12:34.795339",
"icon": "http:\/\/abctech\/images\/home.png",
"created_at": "2017-11-10 12:12:34.795339",
"active_flag": 1,
"id": 1
}
I have extract the "place name" using $..place_name. Now validating the place_name i need to extract the icon. Which means i need to save the icon value which matches the "place name" only
Varibale : new
JSON extractor 1 : $..place_name (second value so only using $..)
Varibale : abc
JSON extractor 2:$..[?(#.place_name==${new})].icon
Matc No (o for random): -1
The value is not passing any suggestion
i have tried with this extarctor also JSON extractor 2:$..[?(#.place_name=='${new}')].icon
Match random i am taking as -1 because i am passing the value in for each controller
I don't find any issue with you approach, it is working fine. I have tried with your payload and changed your payload with multiple value. Both are working fine.
With your payload where single place_name is there,
With multiple value for icon:
Passed the value to for each controller

Powerautomate Parsing JSON Array

I've seen the JSON array questions here and I'm still a little lost, so could use some extra help.
Here's the setup:
My Flow calls a sproc on my DB and that sproc returns this JSON:
{
"ResultSets": {
"Table1": [
{
"OrderID": 9518338,
"BasketID": 9518338,
"RefID": 65178176,
"SiteConfigID": 237
}
]
},
"OutputParameters": {}
}
Then I use a PARSE JSON action to get what looks like the same result, but now I'm told it's parsed and I can call variables.
Issue is when I try to call just, say, SiteConfigID, I get "The output you selected is inside a collection and needs to be looped over to be accessed. This action cannot be inside a foreach."
After some research, I know what's going on here. Table1 is an Array, and I need to tell PowerAutomate to just grab the first record of that array so it knows it's working with just a record instead of a full array. Fair enough. So I spin up a "Return Values to Virtual Power Agents" action just to see my output. I know I'm supposed to use a 'first' expression or a 'get [0] from array expression here, but I can't seem to make them work. Below are what I've tried and the errors I get:
Tried:
first(body('Parse-Sproc')?['Table1/SiteConfigID'])
Got: InvalidTemplate. Unable to process template language expressions in action 'Return_value(s)_to_Power_Virtual_Agents' inputs at line '0' and column '0': 'The template language function 'first' expects its parameter be an array or a string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#first for usage details.'.
Also Tried:
body('Parse-Sproc')?['Table1/SiteconfigID']
which just returns a null valued variable
Finally I tried
outputs('Parse-Sproc')?['Table1']?['value'][0]?['SiteConfigID']
Which STILL gives me a null-valued variable. It's the worst.
In that last expression, I also switched the variable type in the return to pva action to a string instead of a number, no dice.
Also, changed 'outputs' in that expression for 'body' .. also no dice
Here is a screenie of the setup:
To be clear: the end result i'm looking for is for the system to just return "SiteConfigID" as a string or an int so that I can pipe that into a virtual agent.
I believe this is what you need as an expression ...
body('Parse-Sproc')?['ResultSets']['Table1'][0]?['SiteConfigID']
You can see I'm just traversing down to the object and through the array to get the value.
Naturally, I don't have your exact flow but if I use your JSON and load it up into Parse JSON step to get the schema, I am able to get the result. I do get a different schema to you though so will be interesting to see if it directly translates.

Accessing fields in a GO structure

I am new to the Golang world and trying to parse a json response returned by AWS API.
I've tried parsing the result by dot notation and seem to get success in the higher levels. Below is what my experimentation resulted to.
For brevity I excluded other fields
Test 1
fmt.Println(result)
returns
{
DBClusterSnapshots: [{
Status: "available"
}]
}
Test 2
fmt.Println(result.DBClusterSnapshots[0])
returns
{
Status: "available"
}
Test 3
fmt.Println(result.DBClusterSnapshots[0].Status)
returns what seem to be a reference to an object
0xc0001e74c8
Given the last example (Test 3) how do I parse it properly to get the value of Status which is "available"
As pointed out by #mkopriva
Status is a pointer and therefore need to be dereference when intending to extract the string.
so to achieve extracting the value of status we can dereference it like this.
s := *result.DBClusterSnapshots[0].Status
fmt.Println(s)

"Error: imported content is empty" when using =IMPORTXML() for a feed

If I input =IMPORTXML("http://dilbert.com/feed") I get all the feed content, but when I input =IMPORTXML("http://dilbert.com/feed","//updated")
I get #N/A: Error: imported content is empty.
Which XPath have I to use to return only the set of <updated> entries field?
P.S.: I don't want to use =IMPORTFEED() because it can return only some predefined feed item fields.
How about this? http://dilbert.com/feed is in a cell "A1".
=IMPORTXML(A1,"//*[local-name()='updated']")
Result :
Reference :
https://www.w3.org/TR/xpath/
If this was not what you want, I'm sorry.
Edit :
=IMPORTXML(A1,"//*[local-name()='entry']//*[local-name()='updated']")

Is it safe to parse json with YAML.load?

I am using ruby 2.1.0
I have a json file.
For example: test.json
{
"item":[
{"apple": 1},
{"banana": 2}
]
}
Is it safe to load this file with YAML.load?
YAML.load(File.read('test.json'))
I am trying to load a file which is in either json or yaml format.
YAML can load JSON
YAML.load('{"something": "test", "other": 4 }')
=> {"something"=>"test", "other"=>4}
JSON will not be able to load YAML.
JSON.load("- something\n")
JSON::ParserError: 795: unexpected token at '- something'
There will be some obscure cases that work and produce different output.
YAML.load("")
=> false
JSON.load("")
=> nil
But generally the YAML construct is not JSON compliant.
So, try the JSON.load first because it's probably better at obscure JSON things.Catch the JSON::ParserError error and fall back to YAML.load.
In recent work I did I found a corner case of the sort alluded to by Matt. For example
puts JSON.load('{"x": "foo\/bar"}')['x']
succeeds in printing
foo/bar
despite the gratuitous escaping¹ whereas
puts YAML.load('{"x": "foo\/bar"}')['x']
fails:
Psych::SyntaxError ((<unknown>): found unknown escape character while parsing a quoted scalar at line 1 column 7)
¹In this case by Java as per net.sf.json.util.JSONUtils.quote. Note that they forgot to do the same quoting in their own Javadoc, ironically enough, so you have to browse source to understand!

Resources