【问题标题】:Create blob outputting JSON to a single line (Azure Logic App)创建将 JSON 输出到单行的 blob(Azure 逻辑应用)
【发布时间】:2021-07-18 12:59:33
【问题描述】:

我的创建 blob 函数将整个 blob 内容输出到一行而不是标准 JSON 格式。

原始输入:

[
  {
    "AadTenantId_g": "",
    "ActionIdBefore_g": "",
    "ActionId_g": "",
    "ActionSource_s": "",
    "Activity_s": "",
    "ApplicationId_g": "",
    "ApplicationId_s": "",
    "ApplicationName_s": "",
    "Computer": "",
    "ContentIdBefore_g": "",
    "ContentId_g": "",
    "DataState_s": "",
    "DeviceId_g": "",
    "DeviceId_s": "",
    "DiscoveredInformationTypes_s": "",
    "IPv4_s": "",
    "InformationTypesAbove55_s": "",
    "InformationTypesAbove65_s": "",
    "InformationTypesAbove75_s": "",
    "InformationTypesAbove85_s": "",
    "InformationTypesAbove95_s": "",
    "InformationTypes_s": "",
    "IsLabelChanged_b": null,
    "IsProtectionChanged_b": null,
    "LabelIdBeforeAction_g": "",
    "LabelId_g": "",
    "LabelNameBefore_s": "",
    "LabelName_s": "",
    "LastModifiedBy_s": "",
    "LastModifiedDate_t": null,
    "Location_s": "",
    "LogId_g": "",
    "MG": "",
    "MachineName_s": "",
    "ManagementGroupName": "",
    "ObjectId_s": "",
    "Operation_s": "",
    "ParentLabelNameBefore_s": "",
    "ParentLabelName_s": "",
    "Platform_s": "",
    "ProcessName_g": "",
    "ProcessName_s": "",
    "ProcessVersion_s": "",
    "ProductVersion_s": "",
    "ProtectedBeforeAction_b": null,
    "Protected_b": false,
    "ProtectionOwnerBefore_s": "",
    "ProtectionOwner_s": "",
    "ProtectionTime_t": null,
    "ProtectionTypeBefore_s": "",
    "ProtectionType_s": "",
    "RawData": "",
    "RecommendedLabelId_g": "",
    "RecommendedLabelName_s": "",
    "ResultStatus": "",
    "ResultStatus_s": "",
    "SensitivityChange_s": "",
    "SourceSystem": "",
    "TemplateIdBefore_g": "",
    "TemplateId_g": "",
    "TenantId": "",
    "TimeGenerated": "",
    "Type": "",
    "UserId_s": "",
    "UserJustification_s": "",
    "Version_s": "",
    "Workload_s": "",
    "_ResourceId": "",
    "dynamicInformationTypes_s": null
  }
]

输出:

[{"AadTenantId_g":"","ActionIdBefore_g":"","ActionId_g":"","ActionSource_s":"","Activity_s":"","ApplicationId_g":"","ApplicationId_s":"","ApplicationName_s":"","Computer":"","ContentIdBefore_g":"","ContentId_g":"","DataState_s":"","DeviceId_g":"","DeviceId_s":"","DiscoveredInformationTypes_s":"","IPv4_s":"","InformationTypesAbove55_s":"","InformationTypesAbove65_s":"","InformationTypesAbove75_s":"","InformationTypesAbove85_s":"","InformationTypesAbove95_s":"","InformationTypes_s":"","IsLabelChanged_b":null,"IsProtectionChanged_b":null,"LabelIdBeforeAction_g":"","LabelId_g":"","LabelNameBefore_s":"","LabelName_s":"","LastModifiedBy_s":"","LastModifiedDate_t":null,"Location_s":"","LogId_g":"","MG":"","MachineName_s":"","ManagementGroupName":"","ObjectId_s":"","Operation_s":"","ParentLabelNameBefore_s":"","ParentLabelName_s":"","Platform_s":"","ProcessName_g":"","ProcessName_s":"","ProcessVersion_s":"","ProductVersion_s":"","ProtectedBeforeAction_b":null,"Protected_b":false,"ProtectionOwnerBefore_s":"","ProtectionOwner_s":"","ProtectionTime_t":null,"ProtectionTypeBefore_s":"","ProtectionType_s":"","RawData":"","RecommendedLabelId_g":"","RecommendedLabelName_s":"","ResultStatus":"","ResultStatus_s":"","SensitivityChange_s":"","SourceSystem":"","TemplateIdBefore_g":"","TemplateId_g":"","TenantId":"","TimeGenerated":"","Type":"","UserId_s":"","UserJustification_s":"","Version_s":"","Workload_s":"","_ResourceId":"","dynamicInformationTypes_s":null}]

我认为正文的 MediaType 是问题所在,因为 MediaType = application/octet-stream

此问题纯粹位于创建 blob 阶段。

任何帮助将不胜感激 - 谢谢。

【问题讨论】:

    标签: json azure blob azure-logic-apps azure-blob-storage


    【解决方案1】:

    您可以在“create blob”连接器的定义中“手动”添加这样一行。

    "headers": {
    "content-type": "application/json"
    }
    

    【讨论】:

    • 我已经设置了这个标题。你明白为什么 blob 会将 JSON 格式化为一行吗?
    【解决方案2】:

    查看您的 Create blob 函数会很有帮助,但我通过向 JSON.stringify() 方法添加可选参数解决了这个问题,我用它来准备要上传的 JSON 数据:

    JSON.stringify(myJson, null, 4)

    null 的值是 replacer 参数,我们不使用它,数字 4 代表空格参数 -> 缩进的空格数 -> 只是它使 JSON 看起来像可读的 JSON:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-17
      • 2020-05-07
      • 2020-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-01
      • 2020-05-01
      相关资源
      最近更新 更多