Karate: Using data-driven embedded template approach for API testing

CSV is only for “flat” structures, so trying to mix that with JSON is too ambitious in my honest opinion. Please look for another framework if needed 🙂

That said I see 2 options:

a) use proper quoting and escaping in the CSV

b) refer to JSON files

Here is an example:

Scenario Outline:
* json foo = foo
* print foo

Examples:
| read('test.csv') |

And test.csv is:

foo,bar
"{ a: 'a1', b: 'b1' }",test1
"{ a: 'a2', b: 'b2' }",test2

I leave it as an exercise to you if you want to escape double-quotes. It is possible.

Option (b) is you can refer to stand-alone JSON files and read them:

foo,bar
j1.json,test1
j2.json,test2

And you can do * def foo = read(foo) in your feature.

Leave a Comment