Menu
Coddy logo textTech

Complete Search Implementation

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

As a final challenge, you'll need to complete the search implementation, that takes the query filter string as input from the UI.

And returns a filtered list from the complete JSON list available in the backend.

challenge icon

Challenge

Medium

Write a function search that gets,

  • filter_query - string - Input string in the format - 
  • full_json - string - the complete JSON records. A sample of the entire list is given below:

And outputs mixed-array, which is …


Example:

Input -

 type=user
{"result": [
{  
  "name": "Robert McNally",  
  "city": "Hawaii",  
  "type": "user", 
  "gender": "M"
}, {  
  "name": "Elizabeth Minelli",
  "city": "Hawaii",  
  "type": "user",
  "gender": "F"
}, {  
  "name": "Friendly Neighborhood Coder",  
  "city": "Trivandrum",
  "type": "page" },
{
  "name": "Coddy Official",
  "city": "Haifa",
  "type": "page" 
}
]
}

Expected Output - [{'name': 'Robert McNally', 'city': 'Hawaii', 'type': 'user', 'gender': 'M'}, {'name': 'Elizabeth Minelli', 'city': 'Hawaii', 'type': 'user', 'gender': 'F'}] 

 

Explanation - The filter is on type=user. Your python function should filter out any JSON object from the result JSON array where type=user.

Try it yourself

def search(filter_query, full_json):
    # Write code here

All lessons in Social media Search Project - Python JSON Fundamentals

2Social Media Users JSON

Familiarizing with the JSON

5Final Steps

Complete Search ImplementationNext steps

3Basic Search Implementation

Get All RecordsSearch by User/Page