0

I am passing the raw data and removing unwanted slash and trying to convert to json format, unable to proceed.

json spot = {"LoginDetails":"{\"firstName\":\"abcd\",\"lastName\":\"\",\"middleName\":\"\",\"phoneNumber\":\"6944000000\",\"phoneCountryCode\":\"+91\",\"dob\":\"1945-02-22\"}"}
string a = spot
def ab = a.replace("\\", "")
json st = ab

And request st When method POST Then status 200

Getting error

net.minidev.json.parser.ParseException: Unexpected token f

How to resolve this issue and convert the above payload into json format?

NOTE: After conversion to json firstname, phonenumber should be passed dynamically from the preceding API calls.

James Z
  • 12,209
  • 10
  • 24
  • 44
Swedha
  • 1
  • 2
  • I don't understand this question at all so I pass. see if this answer helps: https://stackoverflow.com/a/68411097/143475 – Peter Thomas Aug 04 '22 at 15:30

1 Answers1

0

If u want escape slash with json, you could try

a.replaceAll("\\", "\\\\")

or change it to unicode.

a.replaceAll("\\", "\u005C")

Both of them is workable for browser but not sure for karate, maybe you need change a bit by yourself.

Hill Liu
  • 1
  • 2