Hi all,
I'm stucked with this issue :
I have a json object like that :
{
"key1": "",
"key2": "1/10",
"key3": "1/1,1/2,1/3,1/5",
"key4": "1/24",
"keyX": "1/1,1/2,1/3,1/5,1/4"
}
I want to return the key name for a given value.
For example, if I know a value (eg. 1/24), I want to get the key name (eg. key4).
the key name are not always the same, so I can't use the parse json tool.
best regards,
Hi,
Thanks for your help, it works 🙂
@Anonymous
With JSON parsing, i do not see a way to get the desired result. I am curious to see if anyone has ideas.
By using String manipulation actions, you can get to the desired result.
Created a sample to get the desired result:
Expression in Compose1:
trim(replace(replace(variables('varJsonString'),'{',''),'}',''))
Expression in Compose2:
split(outputs('Compose_1'),'",')
Expression in above Compose action:
concat(items('Apply_to_each'),'"')
Expressions in Condition:
1st Concat expression:
concat(variables('varInputValue'),',')
2nd Concat expression:
concat(variables('varInputValue'),'"')
In Yes block, Expression in Compose 2:
trim(replace(substring(outputs('Compose'),0,indexOf(outputs('Compose'),':')),'"',''))
Append to array variable: Collecting the matching keys into array
Writing the output in Compose 4
RESULT:
I hope this will be helpful to resolve your issue.
Please mark the reply as Accepted Solution, if my reply is helpful. It will also help other users to consider it as a reference.
NOTE: The above solution can be written much better if we keep performance in view. Give a try.
Regards
Krishna Rachakonda
If this reply helped you to solve the issue, please mark the post as Accepted Solution. Marking this post as Accepted Solution, will help many other users to use this post to solve same or similar issue without re-posting the issue in the group. Saves a lot of time for everyone. |
Hi,
Correct, I need to have all key names that match the value.
kind regards,
@Anonymous
You mentioned about an example 1/24. It seems to be unique.
But, for examples: 1/2 or 1/3 or few other values, they are associated with multiple keys. In these cases, are you expecting to have all the key names which matches the value?
Regards
Krishna Rachakonda
If this reply helped you to solve the issue, please mark the post as Accepted Solution. Marking this post as Accepted Solution, will help many other users to use this post to solve same or similar issue without re-posting the issue in the group. Saves a lot of time for everyone. |
WarrenBelz
146,618
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,957
Most Valuable Professional