Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Start free
JSON Value Type Consistency
00:00
5 left

JSON Value Type Consistency

EasyPython

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 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):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

Sign up free to run or submit. Log in
Code
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.