Netflix | Onsite | Query JSON objects
Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2020-03-13Added By Anonymous
Source: Link
Company: Netflix
Role: L4, L5
Interview Stage: Onsite
Location: unknown
Year: unknown
Original Post Content:
Let's say you have an array of similar json objects. Example object:
{ "field1": "bar", "field2": 1, "field3": true, "field4": [1, 2, 3], "field5": { "nested": { "other": [4, 5] } } ... }
Design a method to query this array. You have to design the code and the format of the query:
def search(docs, query): pass
Query examples:
- Get documents where field 1 is equal to "bar"
- Get documents where field 4 contains (or doesn't contain) 2
- Get documents where field5.nested.other contains 4
- Get docs where field3 is True
- etc.