Google | Onsite coding round | March 2022
Anonymous User
812

Given a json in string format, swap its key and values.
The interviewer was looking for clean maintainable code with test cases.

  1. value is array
  2. value is json
  3. special characters in key and values are handled.

{
"key1": "A",\n" +
"key2": 5,\n" +
"key3": 4.5,\n" +
"key4": { "key5": "value5", "key6": [1,2,3,4,5] }\n" +
}";
Implement method, swapKV(String jsonString, String separator, String keyValueSeparator)

For example: swapKV( jsonString, ",", ":")
The , separates multiple kv entries in json

Comments (1)