Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

JSON Value Type Consistency

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is JSON Value Type Consistency. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Quizlet content services exchange collections of JSON objects for surfaces such as Quizlet Study Sets. Given a list of objects and a key, determine whether every object contains that key with the same JSON value type.

The JSON type categories are null, boolean, number, string, array, and object. Treat all numeric values as the number type, and ensure booleans are not classified as numbers. If any object is missing the key, return False. An empty input list is valid and returns True.

Formal Specification

Implement verify_json_key_types(objects, key).

  • objects is a list of JSON objects represented as Python dictionaries.
  • key is a non-empty string.
  • Return a boolean indicating whether every object contains key and all corresponding values have the same JSON type.
  • Only the top-level type of the value associated with key matters. Nested contents do not need to match.

Constraints

  • 1 <= len(objects) <= 10^5
  • Each object contains at most 10^3 key-value pairs
  • Values are valid JSON values
  • The requested key may be absent from an object
  • All numbers use the single JSON type category number

Function Signature

def verify_json_key_types(objects, key):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output