<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Handling JSON Data in CSV Files During Pipeline Execution in Fabric in Pipelines</title>
    <link>https://community.fabric.microsoft.com/t5/Pipelines/Handling-JSON-Data-in-CSV-Files-During-Pipeline-Execution-in/m-p/4086649#M4908</link>
    <description>&lt;P&gt;I need to upload data to S3 in CSV format, which I ingest from Fabric DWH. Produced CSV file contains JSON data within a field.&lt;/P&gt;&lt;P&gt;Occasionally, the pipeline copy activity breaks the data in this scenario. Each JSON field and JSON key is parsed for a not corresponding column.&lt;/P&gt;&lt;P&gt;Changing the delimiter in settings don't solve the issue.&lt;/P&gt;&lt;P&gt;Any ideas how it can be solved?&lt;/P&gt;</description>
    <pubDate>Wed, 07 Aug 2024 11:49:55 GMT</pubDate>
    <dc:creator>pafnuty</dc:creator>
    <dc:date>2024-08-07T11:49:55Z</dc:date>
    <item>
      <title>Handling JSON Data in CSV Files During Pipeline Execution in Fabric</title>
      <link>https://community.fabric.microsoft.com/t5/Pipelines/Handling-JSON-Data-in-CSV-Files-During-Pipeline-Execution-in/m-p/4086649#M4908</link>
      <description>&lt;P&gt;I need to upload data to S3 in CSV format, which I ingest from Fabric DWH. Produced CSV file contains JSON data within a field.&lt;/P&gt;&lt;P&gt;Occasionally, the pipeline copy activity breaks the data in this scenario. Each JSON field and JSON key is parsed for a not corresponding column.&lt;/P&gt;&lt;P&gt;Changing the delimiter in settings don't solve the issue.&lt;/P&gt;&lt;P&gt;Any ideas how it can be solved?&lt;/P&gt;</description>
      <pubDate>Wed, 07 Aug 2024 11:49:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Pipelines/Handling-JSON-Data-in-CSV-Files-During-Pipeline-Execution-in/m-p/4086649#M4908</guid>
      <dc:creator>pafnuty</dc:creator>
      <dc:date>2024-08-07T11:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: Handling JSON Data in CSV Files During Pipeline Execution in Fabric</title>
      <link>https://community.fabric.microsoft.com/t5/Pipelines/Handling-JSON-Data-in-CSV-Files-During-Pipeline-Execution-in/m-p/4088014#M4916</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="786334" data-lia-user-login="pafnuty" class="lia-mention lia-mention-user"&gt;pafnuty&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a problem with data interruption during the pipeline replication process which may be related to the data format. You can consider doing some pre-processing on json data. For example,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Base64 encoding. The JSON data is encoded in base64 format to ensure that it does not interfere with the CSV structure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;import base64
import csv

# Sample JSON data
json_data = '{"key1": "value1", "key2": "value2"}'

# Encode JSON data in base64
encoded_json = base64.b64encode(json_data.encode()).decode()

# Write to CSV
with open('output.csv', 'w', newline='') as csvfile:
    writer = csv.writer(csvfile)
    writer.writerow(['id', 'json_data'])
    writer.writerow([1, encoded_json])
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Escape special characters. Escape special characters in JSON data to prevent parsing problems.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;import csv
import json

# Sample JSON data
json_data = '{"key1": "value1", "key2": "value2"}'

# Escape special characters
escaped_json = json.dumps(json.loads(json_data))

# Write to CSV
with open('output.csv', 'w', newline='') as csvfile:
    writer = csv.writer(csvfile)
    writer.writerow(['id', 'json_data'])
    writer.writerow([1, escaped_json])
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Flatten the JSON data. Convert JSON data to a flat structure before writing it to CSV.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;import csv
import json

# Sample JSON data
json_data = '{"key1": "value1", "key2": "value2"}'
json_dict = json.loads(json_data)

# Write to CSV
with open('output.csv', 'w', newline='') as csvfile:
    writer = csv.writer(csvfile)
    writer.writerow(['id'] + list(json_dict.keys()))
    writer.writerow([1] + list(json_dict.values()))
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hopefully this gives you some ideas.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Nono Chen&lt;/P&gt;
&lt;P&gt;If this &lt;STRONG&gt;&lt;EM&gt;post&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;helps, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Accept it as the solution&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Aug 2024 01:53:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Pipelines/Handling-JSON-Data-in-CSV-Files-During-Pipeline-Execution-in/m-p/4088014#M4916</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-08-08T01:53:30Z</dc:date>
    </item>
  </channel>
</rss>

