Code to flatten a nested json object