Google Interview Question for SDE1s
- 0of 0 votes
AnswersJSON parsing is an essential toolkit in modern web development. Whether you are on the client side or server side, these methods need to be fast, efficient and dependable. But what if one day...
- ajay.raj December 14, 2017 in United States
Suddenly, all of the JSON parser libraries went missing.
You have been called upon to save us all from impending doom.
Please re-implement the standard json parsing methods in your favorite language and restore the world to it's natural order.
Subproblem #1
Write a function, dictionaryToJson to convert a dictionary into a string.
For example, assuming you have dictionary like: dict(“a”: “apple”, “b”: dict(“b”: “blueberry”, “c”: “cranberry”)), the key field is always a string type, the value field could be a string type or a nested dictionary type. And the output would be "{a:apple,b:{b:blueberry,c:cranberry}}"
Subproblem #2
Write a reverse function, jsonToDictionary to convert a string into a dictionary.
Convert a string into the dictionary. e.g., given the input of “{a:apple,b:{b:blueberry,c:cranberry}}”, output dict(“a”: “apple”, “b”: dict(“b”: “blueberry”, “c”: “cranberry”)).
The names and values only contains letters. You can assume that there is no error in the input. You should not use regular expressions.| Report Duplicate | Flag | PURGE
Google SDE1