JSON文件在ADF数据流中生成时带有列名和”\”符号。

huangapple go评论54阅读模式
英文:

JSON file in ADF Data Flow is generating with Column Name and "\" symbol

问题

以下是要翻译的内容:

我有一个CSV文件中的以下数据。

ID userId Name
719A070E-4874-E811-9CCE-02152146006A 123 Joe
5d7d0a74-f1b9-483a-8e9f-c7f45ccfeda0 456 Mike

现在,我需要使用Azure Data Factory的Data Flow生成以下JSON,

{
    {
        "719A070E-4874-E811-9CCE-02152146006A":{
                 "userId":"123",
                  "Name":"Joe"
             }    
    },
    {
        "5d7d0a74-f1b9-483a-8e9f-c7f45ccfeda0":{
                 "userId":"456",
                  "Name":"Mike"
             }    
    }
 }

我已经为此添加了Data Flow,并进行了一些转换。在这些转换之后,我可以将JSON数据带入到一个名为'jsondata'的派生列中,现在我需要生成一个只包含该JSON字符串数据的文件。但是,在生成json的sink(带有json数据集)中,该列名被添加为属性。如何避免这种情况?

实际结果:

{"jsondata": {{\"719A070E-4874-E811-9CCE-02152146006A\":{
                 \"userId\":\"123\",
                  \"Name\":\"Joe\"
             }    
    },
    {
        \"5d7d0a74-f1b9-483a-8e9f-c7f45ccfeda0\":{
                 \"userId\":\"456\",
                  \"Name\":\"Mike\"
             }    
    }
 }}

期望结果:

{
    {
        "719A070E-4874-E811-9CCE-02152146006A":{
                 "userId":"123",
                  "Name":"Joe"
             }    
    },
    {
        "5d7d0a74-f1b9-483a-8e9f-c7f45ccfeda0":{
                 "userId":"456",
                  "Name":"Mike"
             }    
    }
 }

列名'myjson'和转义字符\不应添加到我的JSON输出文件中。(我尝试过用replace来移除\,但没有成功)

Sink设置:

JSON文件在ADF数据流中生成时带有列名和”\”符号。
JSON文件在ADF数据流中生成时带有列名和”\”符号。

以下是SINK的数据预览。我需要生成一个仅包含列(jsondata)中数据的JSON。我不需要将标题(jsondata)添加为JSON文件的属性。

JSON文件在ADF数据流中生成时带有列名和”\”符号。

英文:

I have a below data in csv file.

ID userId Name
719A070E-4874-E811-9CCE-02152146006A 123 Joe
5d7d0a74-f1b9-483a-8e9f-c7f45ccfeda0 456 Mike

Now, I need to generate below json using Azure Data Factory Data Flow,

{
    {
        "719A070E-4874-E811-9CCE-02152146006A":{
                 "userId":"123",
                  "Name":"Joe"
             }    
    },
    {
        "5d7d0a74-f1b9-483a-8e9f-c7f45ccfeda0":{
                 "userId":"456",
                  "Name":"Mike"
             }    
    }
 }

I have added Data Flow for this and made few transformation. After this transformations, I can able to bring the JSON data into a single column as JSON string. Now I need to generate a file with only that json string data in the derived column 'jsondata'. But that Column name is added as attribute while generating json in sink (with json dataset). How to avoid this?

Actual Result:

{"jsondata": {{\"719A070E-4874-E811-9CCE-02152146006A\":{
                 \"userId\":\"123\",
                  \"Name\":\"Joe\"
             }    
    },
    {
        \"5d7d0a74-f1b9-483a-8e9f-c7f45ccfeda0\":{
                 \"userId\":\"456\",
                  \"Name\":\"Mike\"
             }    
    }
 }}

Expected Result:

{
    {
        "719A070E-4874-E811-9CCE-02152146006A":{
                 "userId":"123",
                  "Name":"Joe"
             }    
    },
    {
        "5d7d0a74-f1b9-483a-8e9f-c7f45ccfeda0":{
                 "userId":"456",
                  "Name":"Mike"
             }    
    }
 }

Column name 'myjson' and escape character \ should not be added into my json output file. (I tried replace to remove \ but it didn't worked out)

Sink Settings:
JSON文件在ADF数据流中生成时带有列名和”\”符号。
JSON文件在ADF数据流中生成时带有列名和”\”符号。

Below is the Data Preview of SINK. I need to generate json with data in column (jsondata) only. I don't need the header (jsondata) to add as attribute in json file.
JSON文件在ADF数据流中生成时带有列名和”\”符号。

答案1

得分: 1

以下是代码部分的翻译:

  • Ignore the transformations I made in the image. Now concat [ and ] to this value to make it a set of objects.

  • Instead of creating a JSON dataset, create a DelimitedText dataset with output file name as required with .json extension (this would render the output file as JSON even though the dataset in delimited text).

  • Use the sink dataset configurations as shown in the below image (quote character and escape character).

  • This would generate a file which would be rendered as JSON with the following data:

  • Please refer to the images for visual guidance.

英文:

Since the column is string type, the output data in not as expected. Since you have the jsondata column value as shown below:

{
        "719A070E-4874-E811-9CCE-02152146006A":{
                 "userId":"123",
                  "Name":"Joe"
             }    
    },
    {
        "5d7d0a74-f1b9-483a-8e9f-c7f45ccfeda0":{
                 "userId":"456",
                  "Name":"Mike"
             }    
    }

JSON文件在ADF数据流中生成时带有列名和”\”符号。

  • Ignore the transformations I made in the image. Now concat [ and ] to this value to make it a set of objects.

JSON文件在ADF数据流中生成时带有列名和”\”符号。

  • Instead of creating a JSON dataset, create a DelimitedText dataset with output file name as required with .json extension (this would render the output file as JSON even though the dataset in delimited text).

JSON文件在ADF数据流中生成时带有列名和”\”符号。

  • Use the sink dataset configurations as shown in the below image (quote character and escape character):

JSON文件在ADF数据流中生成时带有列名和”\”符号。

  • This would generate a file which would be rendered as JSON with the following data:
[
   {
      "719A070E-4874-E811-9CCE-02152146006A":{
         "userId":"123",
         "Name":"Joe"
      }
   },
   {
      "5d7d0a74-f1b9-483a-8e9f-c7f45ccfeda0":{
         "userId":"456",
         "Name":"Mike"
      }
   }
]

JSON文件在ADF数据流中生成时带有列名和”\”符号。

huangapple
  • 本文由 发表于 2023年5月29日 14:42:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76355168.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定