<?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 Replace one tag in a Jason file in the data bricks table . in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/replace-one-tag-in-a-jason-file-in-the-data-bricks-table/m-p/80205#M35961</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is a column (src_json) in emp_table . I need to replace (ages to age )in each json in the src_json column in emp_table.&lt;/P&gt;&lt;P&gt;Can you pls suggest the best way to do it .&lt;/P&gt;</description>
    <pubDate>Tue, 23 Jul 2024 19:40:57 GMT</pubDate>
    <dc:creator>Bhabs</dc:creator>
    <dc:date>2024-07-23T19:40:57Z</dc:date>
    <item>
      <title>Replace one tag in a Jason file in the data bricks table .</title>
      <link>https://community.databricks.com/t5/data-engineering/replace-one-tag-in-a-jason-file-in-the-data-bricks-table/m-p/80205#M35961</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is a column (src_json) in emp_table . I need to replace (ages to age )in each json in the src_json column in emp_table.&lt;/P&gt;&lt;P&gt;Can you pls suggest the best way to do it .&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2024 19:40:57 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/replace-one-tag-in-a-jason-file-in-the-data-bricks-table/m-p/80205#M35961</guid>
      <dc:creator>Bhabs</dc:creator>
      <dc:date>2024-07-23T19:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: Replace one tag in a Jason file in the data bricks table .</title>
      <link>https://community.databricks.com/t5/data-engineering/replace-one-tag-in-a-jason-file-in-the-data-bricks-table/m-p/80216#M35964</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/113430"&gt;@Bhabs&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;You can do it in following way (assuming that src_json contains json string):&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from pyspark.sql import SparkSession
from pyspark.sql.functions import col, expr

spark = SparkSession.builder.appName("Replace JSON Keys").getOrCreate()

data = [
    ('{"name": "John", "ages": 30, "department": "HR"}',),
    ('{"name": "Jane", "ages": 25, "department": "Finance"}',),
    ('{"name": "Doe", "ages": 35, "department": "IT"}',)
]


columns = ["src_json"]
emp_table = spark.createDataFrame(data, columns)

# Use expr to update the JSON string
emp_table = emp_table.withColumn("src_json", expr("regexp_replace(src_json, '\"ages\"', '\"age\"')"))

emp_table.show(truncate=False)&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 23 Jul 2024 20:55:13 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/replace-one-tag-in-a-jason-file-in-the-data-bricks-table/m-p/80216#M35964</guid>
      <dc:creator>szymon_dybczak</dc:creator>
      <dc:date>2024-07-23T20:55:13Z</dc:date>
    </item>
  </channel>
</rss>

