简体   繁体   English

电源自动化:JSON 格式问题

[英]Power automate: JSON formatting issues

I am using excel to generate a JSON file via a power automate flow.我正在使用 excel 通过电源自动流程生成一个 JSON 文件。 I have most of the functionality working but am stuck on a formatting issue where lists are being outputted as objects.我的大部分功能都可以正常工作,但我遇到了一个格式问题,即列表被输出为对象。

This is the format I need: "_source": { "title": null, "first_name": { "value": "Tony", "source": "48fa2a08-9137-49fa-8a7d-1d85570b7e5d" }, "last_name": { "value": "Stark", "source": "48fa2a08-9137-49fa-8a7d-1d85570b7e5d" }, "full_name": "Tony Stark",...这是我需要的格式: "_source": { "title": null, "first_name": { "value": "Tony", "source": "48fa2a08-9137-49fa-8a7d-1d85570b7e5d" }, "last_name": { "value": "Stark", "source": "48fa2a08-9137-49fa-8a7d-1d85570b7e5d" }, "full_name": "Tony Stark",...

This is the format I am getting: "_source": { "title": null, "first_name": [ { "value": "Tony", "source": "48fa2a08-9137-49fa-8a7d-1d85570b7e5d" } ], "last_name": [ { "value": "Stark", "source": "48fa2a08-9137-49fa-8a7d-1d85570b7e5d" } ], "full_name": ["Tony Stark"],...这是我得到的格式: "_source": { "title": null, "first_name": [ { "value": "Tony", "source": "48fa2a08-9137-49fa-8a7d-1d85570b7e5d" } ], "last_name": [ { "value": "Stark", "source": "48fa2a08-9137-49fa-8a7d-1d85570b7e5d" } ], "full_name": ["Tony Stark"],...

I am composing this in the following way:我正在按以下方式撰写:

在此处输入图像描述

How do I get rid of the square brackets?如何摆脱方括号?

Any help would be greatly appreciated.任何帮助将不胜感激。 TIA TIA

The output result of your data operations for (eg) first_name is an array. output (例如) first_name的数据操作结果是一个数组。

In order to remove the square brackets, you need to drill down and get the item you want from the array.为了删除方括号,您需要向下钻取并从数组中获取您想要的项目。

Typically, an array is an array because you potentially expect more than one item to exist but in your case, it looks like that's all you expect, therefore, you need to use an expression that will get the first item in the array.通常,数组是一个数组,因为您可能期望存在多个项目,但在您的情况下,它看起来就是您所期望的,因此,您需要使用一个表达式来获取数组中的第一个项目。

To do that, you can wrap the “Output” from the Data Operations step (whatever that action actually is) in a first() expression.为此,您可以将数据操作步骤中的“输出”(无论该操作实际是什么)包装在first()表达式中。

That will return the first object in your array and remove the square brackets.这将返回数组中的第一个 object 并删除方括号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM