1

I am expecting duplicate object to be parsed and post in a request for testing a negative scenario, But karate is sorting and removing the duplicate object

"Test": { "number": "12344", "number": "12344" }

I want both of the "number" to be present after karate parse the json, How can I achieve that

  • Duplicate keys [are not valid in ECMAScript](https://www.ecma-international.org/ecma-262/#sec-json.parse). If you want to use them you have to get a custom parser. – Corvus Feb 07 '23 at 15:36

1 Answers1

0

Sounds like you are trying a negative scenario. Then you have to bypass the Karate JSON parser. Use the text syntax or use a string (note the single-quotes): https://github.com/karatelabs/karate#text

Here is an example:

* url 'https://httpbin.org/post'
* request '{ "Test": { "number": "12344", "number": "12344" } }'
* method post

See this also: https://stackoverflow.com/a/57014394/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248