Skip to content
Foxipa
Code Completion 12 Challenges

Complete the JavaScript JSON Code

Practice JSON parsing, serialization, formatting, and transformation hooks.

Advanced ~8 min read

Challenge 1

Parse JSON text into data

javascript Your answer
const value = JSON.parse( );

Press Ctrl⌘Enter to check your answer

Challenge 2

Serialize an object to JSON text

javascript Your answer
const text = JSON.stringify(data);
// result: 

Press Ctrl⌘Enter to check your answer

Challenge 3

Pretty-print JSON with two-space indentation

javascript Your answer
const text = JSON.stringify(data, null, );

Press Ctrl⌘Enter to check your answer

Challenge 4

Exclude the password property

javascript Your answer
const text = JSON.stringify(user, (key, value) => key === "password" ? undefined : value);
// complete: 

Press Ctrl⌘Enter to check your answer

Challenge 5

Remove a legacy property while parsing

javascript Your answer
const value = JSON.parse(text, (key, value) => key === "legacy" ? undefined : value);
// complete: 

Press Ctrl⌘Enter to check your answer

Challenge 6

Parse a JSON number

javascript Your answer
const count = JSON.parse( );

Press Ctrl⌘Enter to check your answer

Challenge 7

Serialize an array

javascript Your answer
const text = JSON.stringify( );

Press Ctrl⌘Enter to check your answer

Challenge 8

Round-trip JSON-representable data

javascript Your answer
const copy = JSON.parse(JSON.stringify( ));

Press Ctrl⌘Enter to check your answer

Challenge 9

Check whether a value is a raw JSON object

javascript Your answer
const isRaw = JSON.isRawJSON();

Press Ctrl⌘Enter to check your answer

Challenge 10

Create a raw JSON value and check it

javascript Your answer
const raw = JSON.rawJSON("42");
const isRaw = JSON.isRawJSON();

Press Ctrl⌘Enter to check your answer

Challenge 11

Check that an ordinary object is not a raw JSON object

javascript Your answer
const ordinary = { value: 42 };
const isRaw = JSON.isRawJSON();

Press Ctrl⌘Enter to check your answer

Challenge 12

Check a lookalike object rather than trusting its rawJSON property

javascript Your answer
const lookalike = { rawJSON: "42" };
const isRaw = JSON.isRawJSON();

Press Ctrl⌘Enter to check your answer