<?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 Re: How do I create a copy or clone of a dict? in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/How-do-I-create-a-copy-or-clone-of-a-dict/m-p/1030198#M40376</link>
    <description>&lt;P&gt;I want to create a dict, and then create a copy/clone of that dict.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{% set dict = { "a": 1 } %}
{% set copy_of_dict = dict %}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But this code doesn't create two unique dicts, it just assigns the first dict to another variable. And so if I were to append data to either `dict` or `copy_of_dict`, they would both be updated which I do not want.&lt;/P&gt;</description>
    <pubDate>Wed, 21 Aug 2024 12:39:27 GMT</pubDate>
    <dc:creator>jkupczak</dc:creator>
    <dc:date>2024-08-21T12:39:27Z</dc:date>
    <item>
      <title>How do I create a copy or clone of a dict?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/How-do-I-create-a-copy-or-clone-of-a-dict/m-p/1029854#M40363</link>
      <description>&lt;P&gt;The documentation mentions the .copy() function as a solution, but I only get errors when attempting to use it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.hubspot.com/docs/cms/hubl/functions#copy" target="_blank"&gt;https://developers.hubspot.com/docs/cms/hubl/functions#copy&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2024 21:20:42 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/How-do-I-create-a-copy-or-clone-of-a-dict/m-p/1029854#M40363</guid>
      <dc:creator>jkupczak</dc:creator>
      <dc:date>2024-08-20T21:20:42Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a copy or clone of a dict?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/How-do-I-create-a-copy-or-clone-of-a-dict/m-p/1030082#M40366</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/630095"&gt;@jkupczak&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you provide more context about what you're trying to do?&lt;/P&gt;&lt;P&gt;And a screenshot of your codes would be helpful.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Best regards,&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Abraham Ernesto&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2024 08:49:17 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/How-do-I-create-a-copy-or-clone-of-a-dict/m-p/1030082#M40366</guid>
      <dc:creator>GiantFocal</dc:creator>
      <dc:date>2024-08-21T08:49:17Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a copy or clone of a dict?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/How-do-I-create-a-copy-or-clone-of-a-dict/m-p/1030198#M40376</link>
      <description>&lt;P&gt;I want to create a dict, and then create a copy/clone of that dict.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{% set dict = { "a": 1 } %}
{% set copy_of_dict = dict %}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But this code doesn't create two unique dicts, it just assigns the first dict to another variable. And so if I were to append data to either `dict` or `copy_of_dict`, they would both be updated which I do not want.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2024 12:39:27 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/How-do-I-create-a-copy-or-clone-of-a-dict/m-p/1030198#M40376</guid>
      <dc:creator>jkupczak</dc:creator>
      <dc:date>2024-08-21T12:39:27Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a copy or clone of a dict?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/How-do-I-create-a-copy-or-clone-of-a-dict/m-p/1030388#M40382</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/630095"&gt;@jkupczak&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A workaround I have found is to use the to and from json filters to create the copy.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{% set dict = {'a' : 1} %}
{% set copy_of_dict = dict|tojson|fromjson  %}
              
orig: {{dict}}
copy: {{copy_of_dict}}

After Append
{% do dict.put("b",2) %}
orig: {{dict}}
copy: {{copy_of_dict}}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Karla&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2024 17:51:42 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/How-do-I-create-a-copy-or-clone-of-a-dict/m-p/1030388#M40382</guid>
      <dc:creator>KBarnes_Breck</dc:creator>
      <dc:date>2024-08-21T17:51:42Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a copy or clone of a dict?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/How-do-I-create-a-copy-or-clone-of-a-dict/m-p/1030869#M40390</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/630095"&gt;@jkupczak&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Sure, the documentation you provided mentions that you're getting errors while using the .copy() function. The reason you might be getting errors is because the .copy() method creates a shallow copy of the dictionary. This means that the new dictionary contains references to the same objects as the original dictionary. If you modify the copied dictionary, the changes will also be reflected in the original dictionary.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I hope this will help you out. Please mark it as &lt;STRONG&gt;Solution Accepted and upvote&lt;/STRONG&gt; to help another Community member. &lt;BR /&gt;Thanks!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2024 13:33:29 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/How-do-I-create-a-copy-or-clone-of-a-dict/m-p/1030869#M40390</guid>
      <dc:creator>GRajput</dc:creator>
      <dc:date>2024-08-22T13:33:29Z</dc:date>
    </item>
  </channel>
</rss>

