Azure 数据工厂中的 JSON 格式JSON format in Azure Data Factory

适用于: Azure 数据工厂 Azure Synapse Analytics(预览版)

如果要 分析 JSON 文件或以 JSON 格式写入数据 ,请遵循本文中的说明。Follow this article when you want to parse the JSON files or write the data into JSON format .

以下连接器支持 JSON 格式:Amazon S3Azure BlobAzure Data Lake Storage Gen2Azure 文件存储文件系统FTPGoogle 云存储HDFSHTTPSFTPJSON format is supported for the following connectors: Amazon S3, Azure Blob, Azure Data Lake Storage Gen2, Azure File Storage, File System, FTP, Google Cloud Storage, HDFS, HTTP, and SFTP.

数据集属性Dataset properties

有关可用于定义数据集的各部分和属性的完整列表,请参阅数据集一文。For a full list of sections and properties available for defining datasets, see the Datasets article. 本部分提供 JSON 数据集支持的属性列表。This section provides a list of properties supported by the JSON dataset.

属性Property 说明Description 必须Required
typetype 数据集的 type 属性必须设置为 JsonThe type property of the dataset must be set to Json . Yes
locationlocation 文件的位置设置。Location settings of the file(s). 每个基于文件的连接器在 location 下都有其自己的位置类型和支持的属性。Each file-based connector has its own location type and supported properties under location. 请在连接器文章 -> 数据集属性部分中查看详细信息See details in connector article -> Dataset properties section . Yes
encodingNameencodingName 用于读取/写入测试文件的编码类型。The encoding type used to read/write test files.
可用的值如下:"UTF-8"、"UTF-16"、"UTF-16BE"、"UTF-32"、"UTF-32BE"、"US-ASCII"、"UTF-7"、"BIG5"、"EUC-JP"、"EUC-KR"、"GB2312"、"GB18030"、"JOHAB"、"SHIFT-JIS"、"CP875"、"CP866"、"IBM00858"、"IBM037"、"IBM273"、"IBM437"、"IBM500"、"IBM737"、"IBM775"、"IBM850"、"IBM852"、"IBM855"、"IBM857"、"IBM860"、"IBM861"、"IBM863"、"IBM864"、"IBM865"、"IBM869"、"IBM870"、"IBM01140"、"IBM01141"、"IBM01142"、"IBM01143"、"IBM01144"、"IBM01145"、"IBM01146"、"IBM01147"、"IBM01148"、"IBM01149"、"ISO-2022-JP"、"ISO-2022-KR"、"ISO-8859-1"、"ISO-8859-2"、"ISO-8859-3"、"ISO-8859-4"、"ISO-8859-5"、"ISO-8859-6"、"ISO-8859-7"、"ISO-8859-8"、"ISO-8859-9"、"ISO-8859-13"、"ISO-8859-15"、"WINDOWS-874"、"WINDOWS-1250"、"WINDOWS-1251"、"WINDOWS-1252"、"WINDOWS-1253"、"WINDOWS-1254"、"WINDOWS-1255"、"WINDOWS-1256"、"WINDOWS-1257"、"WINDOWS-1258"。Allowed values are as follows: "UTF-8", "UTF-16", "UTF-16BE", "UTF-32", "UTF-32BE", "US-ASCII", "UTF-7", "BIG5", "EUC-JP", "EUC-KR", "GB2312", "GB18030", "JOHAB", "SHIFT-JIS", "CP875", "CP866", "IBM00858", "IBM037", "IBM273", "IBM437", "IBM500", "IBM737", "IBM775", "IBM850", "IBM852", "IBM855", "IBM857", "IBM860", "IBM861", "IBM863", "IBM864", "IBM865", "IBM869", "IBM870", "IBM01140", "IBM01141", "IBM01142", "IBM01143", "IBM01144", "IBM01145", "IBM01146", "IBM01147", "IBM01148", "IBM01149", "ISO-2022-JP", "ISO-2022-KR", "ISO-8859-1", "ISO-8859-2", "ISO-8859-3", "ISO-8859-4", "ISO-8859-5", "ISO-8859-6", "ISO-8859-7", "ISO-8859-8", "ISO-8859-9", "ISO-8859-13", "ISO-8859-15", "WINDOWS-874", "WINDOWS-1250", "WINDOWS-1251", "WINDOWS-1252", "WINDOWS-1253", "WINDOWS-1254", "WINDOWS-1255", "WINDOWS-1256", "WINDOWS-1257", "WINDOWS-1258".
No
compressioncompression 用来配置文件压缩的属性组。Group of properties to configure file compression. 如果需要在活动执行期间进行压缩/解压缩,请配置此部分。Configure this section when you want to do compression/decompression during activity execution. No
typetype
(在 compression 下)( under compression )
用来读取/写入 JSON 文件的压缩编解码器。The compression codec used to read/write JSON files.
允许的值为 bzip2、gzip、deflate、ZipDeflate、TarGzip、snappy 或 lz4 。Allowed values are bzip2 , gzip , deflate , ZipDeflate , TarGzip , snappy , or lz4 . 默认设置是不压缩。Default is not compressed.
注意,复制活动当前不支持“snappy”和“lz4”。Note currently Copy activity doesn't support "snappy" & "lz4".
注意,使用复制活动解压缩 ZipDeflate/TarGzip 文件并将其写入基于文件的接收器数据存储时,默认情况下文件将提取到 <path specified in dataset>/<folder named as source compressed file>/ 文件夹,对复制活动源使用 preserveZipFileNameAsFolder/preserveCompressionFileNameAsFolder 来控制是否以文件夹结构形式保留压缩文件名 。Note when using copy activity to decompress ZipDeflate/TarGzip file(s) and write to file-based sink data store, by default files are extracted to the folder:<path specified in dataset>/<folder named as source compressed file>/, use preserveZipFileNameAsFolder/preserveCompressionFileNameAsFolder on copy activity source to control whether to preserve the name of the compressed file(s) as folder structure.
否。No.
levellevel
(在 compression 下)( under compression )
压缩率。The compression ratio.
允许的值为 OptimalFastestAllowed values are Optimal or Fastest .
- Fastest :尽快完成压缩操作,不过,无法以最佳方式压缩生成的文件。- Fastest: The compression operation should complete as quickly as possible, even if the resulting file is not optimally compressed.
- Optimal :以最佳方式完成压缩操作,不过,需要耗费更长的时间。- Optimal : The compression operation should be optimally compressed, even if the operation takes a longer time to complete. 有关详细信息,请参阅 Compression Level(压缩级别)主题。For more information, see Compression Level topic.
No

下面是 Azure Blob 存储上的 JSON 数据集的示例:Below is an example of JSON dataset on Azure Blob Storage:

{
    "name": "JSONDataset",
    "properties": {
        "type": "Json",
        "linkedServiceName": {
            "referenceName": "<Azure Blob Storage linked service name>",
            "type": "LinkedServiceReference"
        },
        "schema": [ < physical schema, optional, retrievable during authoring > ],
        "typeProperties": {
            "location": {
                "type": "AzureBlobStorageLocation",
                "container": "containername",
                "folderPath": "folder/subfolder",
            },
            "compression": {
                "type": "gzip"
            }
        }
    }
}

复制活动属性Copy activity properties

有关可用于定义活动的各部分和属性的完整列表,请参阅管道一文。For a full list of sections and properties available for defining activities, see the Pipelines article. 本部分提供 JSON 源和接收器支持的属性列表。This section provides a list of properties supported by the JSON source and sink.

若要了解如何从 JSON 文件中提取数据并将其映射到接收器数据存储/格式(反之亦然),请参阅架构映射Learn about how to extract data from JSON files and map to sink data store/format or vice versa from schema mapping.

以 JSON 作为源JSON as source

复制活动的 *source* 节支持以下属性。The following properties are supported in the copy activity *source* section.

属性Property 说明Description 必须Required
typetype 复制活动源的 type 属性必须设置为 JSONSourceThe type property of the copy activity source must be set to JSONSource . Yes
formatSettingsformatSettings 一组属性。A group of properties. 请参阅下面的“JSON 读取设置”表。Refer to JSON read settings table below. No
storeSettingsstoreSettings 有关如何从数据存储读取数据的一组属性。A group of properties on how to read data from a data store. 每个基于文件的连接器在 storeSettings 下都有其自己支持的读取设置。Each file-based connector has its own supported read settings under storeSettings. 请在连接器文章 -> 复制活动属性部分中查看详细信息See details in connector article -> Copy activity properties section . No

formatSettings 下支持的“JSON 读取设置”:Supported JSON read settings under formatSettings:

属性Property 说明Description 必须Required
typetype formatSettings 的 type 必须设置为“JsonReadSettings”。The type of formatSettings must be set to JsonReadSettings . Yes
compressionPropertiescompressionProperties 一组属性,指示如何为给定的压缩编解码器解压缩数据。A group of properties on how to decompress data for a given compression codec. No
preserveZipFileNameAsFolderpreserveZipFileNameAsFolder
(在 compressionProperties->type 下为 ZipDeflateReadSettings( under compressionProperties->type as ZipDeflateReadSettings )
当输入数据集配置了 ZipDeflate 压缩时适用。Applies when input dataset is configured with ZipDeflate compression. 指示是否在复制过程中以文件夹结构形式保留源 zip 文件名。Indicates whether to preserve the source zip file name as folder structure during copy.
- 当设置为 true(默认值)时,数据工厂会将已解压缩的文件写入 <path specified in dataset>/<folder named as source zip file>/- When set to true (default) , Data Factory writes unzipped files to <path specified in dataset>/<folder named as source zip file>/.
- 当设置为 false 时,数据工厂会直接将未解压缩的文件写入 <path specified in dataset>- When set to false , Data Factory writes unzipped files directly to <path specified in dataset>. 请确保不同的源 zip 文件中没有重复的文件名,以避免产生冲突或出现意外行为。Make sure you don't have duplicated file names in different source zip files to avoid racing or unexpected behavior.
No
preserveCompressionFileNameAsFolderpreserveCompressionFileNameAsFolder
(在 compressionProperties->type 下为 TarGZipReadSettings( under compressionProperties->type as TarGZipReadSettings )
当输入数据集配置了 TarGzip 压缩时适用。Applies when input dataset is configured with TarGzip compression. 指示是否在复制过程中以文件夹结构形式保留源压缩文件名。Indicates whether to preserve the source compressed file name as folder structure during copy.
- 当设置为 true(默认值)时,数据工厂会将已解压缩的文件写入 <path specified in dataset>/<folder named as source compressed file>/- When set to true (default) , Data Factory writes decompressed files to <path specified in dataset>/<folder named as source compressed file>/.
- 当设置为 false 时,数据工厂会直接将已解压缩的文件写入 <path specified in dataset>- When set to false , Data Factory writes decompressed files directly to <path specified in dataset>. 请确保不同的源文件中没有重复的文件名,以避免产生冲突或出现意外行为。Make sure you don't have duplicated file names in different source files to avoid racing or unexpected behavior.
No

JSON 作为接收器JSON as sink

复制活动的 *sink* 节支持以下属性。The following properties are supported in the copy activity *sink* section.

属性Property 说明Description 必须Required
typetype 复制活动源的 type 属性必须设置为 JSONSinkThe type property of the copy activity source must be set to JSONSink . Yes
formatSettingsformatSettings 一组属性。A group of properties. 请参阅下面的“JSON 写入设置”表。Refer to JSON write settings table below. No
storeSettingsstoreSettings 有关如何将数据写入到数据存储的一组属性。A group of properties on how to write data to a data store. 每个基于文件的连接器在 storeSettings 下都有其自身支持的写入设置。Each file-based connector has its own supported write settings under storeSettings. 请在连接器文章 -> 复制活动属性部分中查看详细信息See details in connector article -> Copy activity properties section . No

formatSettings 下支持的 JSON 写入设置Supported JSON write settings under formatSettings:

属性Property 说明Description 必须Required
typetype formatSettings 的类型必须设置为 JsonWriteSettingsThe type of formatSettings must be set to JsonWriteSettings . Yes
filePatternfilePattern 指示每个 JSON 文件中存储的数据模式。Indicate the pattern of data stored in each JSON file. 允许的值为:setOfObjects (JSON Lines) 和 arrayOfObjects。Allowed values are: setOfObjects (JSON Lines) and arrayOfObjects . 默认 值为 setOfObjectsThe default value is setOfObjects . 请参阅 JSON 文件模式部分,详细了解这些模式。See JSON file patterns section for details about these patterns. No

JSON 文件模式JSON file patterns

从 JSON 文件复制数据时,复制活动可自动检测并分析以下 JSON 文件模式。When copying data from JSON files, copy activity can automatically detect and parse the following patterns of JSON files. 将数据写入 JSON 文件时,可以在复制活动接收器上配置文件模式。When writing data to JSON files, you can configure the file pattern on copy activity sink.

  • 类型 I:setOfObjectsType I: setOfObjects

    每个文件都包含单一对象、JSON Lines 或串联的对象。Each file contains single object, JSON lines, or concatenated objects.

    • 单一对象 JSON 示例single object JSON example

      {
          "time": "2015-04-29T07:12:20.9100000Z",
          "callingimsi": "466920403025604",
          "callingnum1": "678948008",
          "callingnum2": "567834760",
          "switch1": "China",
          "switch2": "Germany"
      }
      
    • JSON Lines(接收器的默认值)JSON Lines (default for sink)

      {"time":"2015-04-29T07:12:20.9100000Z","callingimsi":"466920403025604","callingnum1":"678948008","callingnum2":"567834760","switch1":"China","switch2":"Germany"}
      {"time":"2015-04-29T07:13:21.0220000Z","callingimsi":"466922202613463","callingnum1":"123436380","callingnum2":"789037573","switch1":"US","switch2":"UK"}
      {"time":"2015-04-29T07:13:21.4370000Z","callingimsi":"466923101048691","callingnum1":"678901578","callingnum2":"345626404","switch1":"Germany","switch2":"UK"}
      
    • 串连的 JSON 示例concatenated JSON example

      {
          "time": "2015-04-29T07:12:20.9100000Z",
          "callingimsi": "466920403025604",
          "callingnum1": "678948008",
          "callingnum2": "567834760",
          "switch1": "China",
          "switch2": "Germany"
      }
      {
          "time": "2015-04-29T07:13:21.0220000Z",
          "callingimsi": "466922202613463",
          "callingnum1": "123436380",
          "callingnum2": "789037573",
          "switch1": "US",
          "switch2": "UK"
      }
      {
          "time": "2015-04-29T07:13:21.4370000Z",
          "callingimsi": "466923101048691",
          "callingnum1": "678901578",
          "callingnum2": "345626404",
          "switch1": "Germany",
          "switch2": "UK"
      }
      
  • 类型 II:arrayOfObjectsType II: arrayOfObjects

    每个文件包含对象的数组。Each file contains an array of objects.

    [
        {
            "time": "2015-04-29T07:12:20.9100000Z",
            "callingimsi": "466920403025604",
            "callingnum1": "678948008",
            "callingnum2": "567834760",
            "switch1": "China",
            "switch2": "Germany"
        },
        {
            "time": "2015-04-29T07:13:21.0220000Z",
            "callingimsi": "466922202613463",
            "callingnum1": "123436380",
            "callingnum2": "789037573",
            "switch1": "US",
            "switch2": "UK"
        },
        {
            "time": "2015-04-29T07:13:21.4370000Z",
            "callingimsi": "466923101048691",
            "callingnum1": "678901578",
            "callingnum2": "345626404",
            "switch1": "Germany",
            "switch2": "UK"
        }
    ]
    

后续步骤Next steps