Search code examples
karateintuit-partner-platform

How to create a deep copy in Karate


How can I create a totally independent copy of a variable in karate. So that changing one doesn't affect the other. I tried simply assigning it to a new variable but it didn't work.

* def copyJson = originalJson

Changing copyJson changes the originalJson too.


Solution

  • This is possible, and explained in the documentation: https://github.com/intuit/karate#copy

    * def original = { key: 'value' }
    # this will create a "deep copy"
    * copy foo = original