Karate - Get CSV column value having space

Viewed 104

I want to get the 'Instrument ID' column value of the below CSV data where the CSV column header having spaces

Instrument ID, Instrument Name
SS-01,TestData

This is my code

* json csvContents = read('instument-info.csv')
* print csvContents
* print csvContents[0] 
* print csvContents[0].Instrument ID

But its throws the below error

01: karate.log('[print]',csvContents[0].Instrument ID)
<<<<
org.graalvm.polyglot.PolyglotException: SyntaxError: Unnamed:1:43 Expected , but found ID
karate.log('[print]',csvContents[0].Instrument ID)
1 Answers

Use the JS "bracket" notation. For example, try this:

* csv data = 
"""
Instrument ID, Instrument Name
SS-01,TestData
"""
* match data[0]['Instrument ID'] == 'SS-01'
Related