简体   繁体   English

使用Azure Logic应用遍历并检查JSON对象属性

[英]Iterating Through and Checking JSON Object Properties using Azure Logic Apps

I am attempting to write an Azure Logic App which will assist with me moving data from my Azure LogAnalytics Workspace and into Azure Table Storage. 我正在尝试编写一个Azure逻辑应用程序,该应用程序将帮助我将数据从Azure LogAnalytics工作区移至Azure表存储中。 As I am performing this task, I continue to get the same error. 在执行此任务时,我继续遇到相同的错误。 Essentially, the LogAnalytics Data has some properties which are assigned null values, but the Azure Table Storage does not allow null values at all - so it simply throws a generic error: 本质上,LogAnalytics数据具有分配了空值的某些属性,但是Azure表存储完全不允许空值-因此,它仅引发一般错误:

Service Code: 400 服务编号:400

"code": "PropertiesNeedValue" “代码”:“ PropertiesNeedValue”

"value": "The values are not specified for all properties in the entity. “ value”:“未为实体中的所有属性指定值。

So, in order to get the Azure Storage Table to accept the data from LogAnalytics, I need to convert any Null Valued properties into a different data type, such as an empty string. 因此,为了使Azure存储表接受LogAnalytics的数据,我需要将所有“空值”属性转换为其他数据类型,例如空字符串。 The issue here is, the data which is stored as JSON Objects, have hundreds of properties with any number of them being null. 这里的问题是,存储为JSON对象的数据具有数百个属性,其中任意多个为null。

I need to be able to iterate through the properties themselves, check if each is null, and then set the property to a different value/data type. 我需要能够遍历属性本身,检查每个属性是否为null,然后将属性设置为其他值/数据类型。

Is this possible using Azure Logic Apps? 使用Azure Logic应用程序可以做到这一点吗?

How would this be implemented? 如何实施?

For the record I am familiar with LogicApps and understand how to use SetProperty(), RemoveProperty(), and how to use the ForEach Loops. 作为记录,我熟悉LogicApps,并了解如何使用SetProperty(),RemoveProperty()以及如何使用ForEach循环。 Thank you!! 谢谢!!

The solution for successful parsing is to modify the schema to allow nulls. 成功解析的解决方案是将架构修改为允许空值。

Modifying Existing schema It can be done in very simple step by modifying type of the object into array of types like shown below: 修改现有模式可以通过将对象的类型修改为如下所示的类型数组的非常简单的步骤来完成:

在此处输入图片说明

Execution that allow nulls to be parsed 允许解析空值的执行

在此处输入图片说明

在此处输入图片说明

We see that this time Logic app did not thrown an exception and would allow us to deal with this null value within our code. 我们看到,这次Logic应用程序没有引发异常,它将使我们能够在代码中处理此null值。

Let's bear in mind that allowing nulls it is not always the best option. 请记住,允许空值并不总是最好的选择。

There is also default values, that could be considered, but everything depends on the context your logic app operates in. 还可以考虑使用默认值,但是默认值取决于逻辑应用程序在其中运行的上下文。

Hope it helps. 希望能帮助到你。

MV MV

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

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