Menu
Coddy logo textTech

Get All Records

Lesson 5 of 10 in Coddy's Social media Search Project - Python JSON Fundamentals course.

When the user doesn't type in anything in the search box and then click on the Search button, the result should display the entire set of records. 

To display the entire list, we just need to return an array of JSON objects each following the below format:

{
	"full_name": "Robert Newell",
	"city": "Hawaii",
	"type": "user"
}

There is ONE problem. The JSON object in our backend service follows this format:

{
	"first_name": "Robert",
	"last_name": "Newell",
	"city": "Hawaii",
	"type": "user"
}

Notice how the first_name and last_name are kept separately? You need to merge this and construct a new JSON object matching the expected output format.

 

challenge icon

Challenge

Easy

Write a function get_all_records that gets,

  • full_json_str - string - the complete database records in JSON string format.

And outputs mixed-dict, which is the entire set of records as a dictionary object.


Example 1:

Input - {"results": [{"first_name": "Aaron", "last_name": "Taylor", "city": "Paris", "type": "user"}]}

Expected Output - {"results": [{"full_name": "Aaron Taylor", "city": "Paris", "type": "user"}]}

Explanation - Input contains a single record in the results JSON array. A new JSON object is constructed and assigned to the JSON array - results. Ultimately, a JSON object containing this results JSON array is returned.

Try it yourself

def get_all_records(full_json_str):
    # Write code here

All lessons in Social media Search Project - Python JSON Fundamentals