Json
38 bites tagged Json — interview questions with model answers, and 60-second explainers.
Implementing a custom filtering Transform stream
Subclass Transform with objectMode, implement _transform to parse each chunk, push only matching objects, and call the callback; handle parse errors. Knowing the Transform stream contract.
res.send vs res.json vs res.end
Send is flexible and sets content type by type, json serializes and sets JSON content type, end is the raw http terminator with no body helpers. how Express sends responses. using res.end to return an object or claiming they.
Parsing JSON bodies with express.json
Register express.json via app.use so it reads the request stream and populates req.body before handlers run, place it before routes. why req.body needs a body parser. expecting req.body to work without any parser.
Reading a POST body from the request stream
Body arrives in chunks via data events, accumulate them, on the end event concatenate and JSON.parse inside try/catch. that req is a readable stream. expecting req.body to exist or parsing before all chunks arrive.
Structured vs unstructured logging
Unstructured logs are free-text lines; structured logs are machine-readable key-value or JSON, enabling reliable parsing, filtering, and aggregation. Why log format matters at scale.
Structured vs unstructured logging: why it matters
Unstructured logs are free-text lines hard to parse; structured logs are machine-readable key-value or JSON records; structure enables reliable querying… understanding of log formats and their impact on observability at scale.
Brand color as a token and CSS custom property
Define a typed color token in JSON, generate a custom property like --color-brand-primary, then reference it with var(). practical token-to-CSS wiring.
Decoding a heterogeneous JSON array by a type field
Peek the type field with a partial decode, switch on it, and decode the concrete type, wrapping each in an enum or boxed protocol value. custom Decodable with a discriminator.
Map JSON keys to differently named Codable properties
Declare a nested CodingKeys enum mapping userID to the raw value "user_id", or set the decoder's keyDecodingStrategy to convertFromSnakeCase for blanket conversion. Codable key customization.
V8 doubles JSON.stringify speed with side-effect-free fast path
V8 doubled JSON.stringify speed with a side-effect-free fast path. Every network and storage serialization of plain objects gets faster with zero code changes. Check your profiles if JSON encoding shows up hot.
How do you store and retrieve a TypeScript object in localStorage?
This tests your knowledge of Web Storage string constraints and JSON serialization. A strong answer covers JSON.stringify on write, JSON.parse on read, and typing the result with a TypeScript interface.
Write a createUser function that POSTs JSON via fetch
Precise fetch configuration for JSON POST requests. A strong answer names method POST, headers Content-Type application/json, and body JSON.stringify(data) with return typing. Red flag: passing the raw object as body or omitting headers.
How do you parse JSON body in a POST Route Handler?
It tests whether you know Next.js App Router Route Handlers use the standard Web Request API. Call await request.json() inside the POST function; handle errors with try-catch and return a 400 for invalid JSON.
JWT: Signed JSON Claim Tokens
A JWT is a signed JSON envelope: it carries claim assertions in JSON, optionally encrypted, and proves who wrote it using either a private secret or a public/private key. Do not treat the payload as hidden unless encryption is actually enabled.
Describe two prompt-based techniques to ensure valid LLM JSON output
This tests output constriction via prompt design. First, embed an exact JSON skeleton with empty values. Second, provide few-shot exemplars mapping inputs to valid JSON. A red flag is suggesting only post-hoc regex repair or larger models.
Serialize a Go struct to JSON and contrast with Rust
This tests fluency in Go's encoding/json versus Rust's derive macro ecosystem. Go: call json.Marshal on exported fields; Rust: derive Serialize, then serde_json::to_string. Red flag: claiming Rust uses std-only serialization or that Go needs external crates.
Structure a POST request to send a Dart object as JSON
Set Content-Type application/json, serialize to Map via toJson, encode with dart:convert jsonEncode, and pass the string as body. Your grasp of HTTP semantics and Dart serialization.
Persist a custom Dart object using shared_preferences
Tests JSON serialization bridging custom objects to primitive-only key-value storage. Strong answer: add toJson/fromJson on User, jsonEncode into SharedPreferences as String, jsonDecode on read. Red flag: proposing direct storage or toString hacks.
Compare manual JSON serialization versus json_serializable
It tests build automation versus manual control in Dart serialization. Manual methods avoid build steps but risk drift; code generation cuts boilerplate but adds compile latency. Claiming code gen slows runtime or that manual is always simpler.
Purpose of factory fromJson constructor in Dart models
Factory fromJson centralizes deserialization, preprocesses Map values before instantiation, and keeps the primary constructor clean. Why factory constructors separate parsing from creation.
Make a GET request with http and parse JSON in Dart
Practical Dart async networking with package:http and dart:convert. Import http, await get(Uri.parse(url)), verify statusCode is 200, then jsonDecode(response.body) as List<Map<String, dynamic>>. Skipping status checks or decoding without a cast.
How do you model Product and safely parse JSON into List<Product>?
Tests bridging dynamic JSON to Dart's type system. A strong answer uses an immutable Product with a factory constructor that validates fields and converts types, mapping over the list. Red flag: leaving everything dynamic or assuming perfect API data.
What is a Dart factory constructor and common use cases?
Explain a factory need not create new instances and can return cached objects or subtypes; contrast with generative ones; give JSON or singleton examples. When Dart factories beat generative constructors.
How do you fetch JSON from a REST API and parse it?
This tests practical fluency with HTTP mechanics and JSON deserialization. A strong answer names the method, URL, and headers; checks the status code; then parses with r.json() or json.loads. A red flag is skipping error handling or confusing GET with POST.
Get Json bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.