












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A comprehensive overview of the json (javascript object notation) data format. Json is a lightweight, text-based data interchange format that is easy for humans to read and write, and easy for machines to parse and generate. It is widely used for transmitting data between a server and a web application as part of the ajax technology stack. The basic syntax and structure of json, including key-value pairs, arrays, and nested objects. It also discusses data types supported in json, such as strings, numbers, booleans, and null. Additionally, the document explores json parsing and serialization using javascript, as well as common use cases and best practices for working with json data. This information would be valuable for students studying web development, data formats, or programming languages that support json, such as javascript, python, and java.
Typology: Exams
1 / 20
This page cannot be seen from the preview
Don't miss anything!













{"name":'John', "age":30} b) {'name':'John', 'age':30} c) {"name":"John", "age":30} d) {name:"John", age:30}Rationale: JSON requires double quotes for both keys and string values. Option c) follows this format correctly.
var jsonString = '{"name": "Alice", "active": true}'; var obj = JSON.parse(jsonString); console.log(obj.active); a) "true" b) true c) undefinedRationale: The correct way to add a new key-value pair is using dot notation or array-like notation with the assignment operator (=).
Rationale: JSON is designed for structured data and does not support functions or comments. It has limitations in terms of number precision as per IEEE 754 standards.
JSON.stringify()Rationale: JSON.stringify() converts JavaScript objects to a JSON string.
application/json, while(1);Rationale: Setting the content-type correctly or prefixing responses prevents JSON hijacking.
[], boolean valuesRationale: Arrays use square brackets and can hold various types of data.
try...catch blockRationale: The try...catch block is used to handle errors that may occur during JSON.parse().
Rationale: JSON does not have a native date type; dates are typically represented as strings.
Rationale: JSON follows a strict syntax that disallows trailing commas.
Rationale: JSON cannot include functions, making it unsuitable for scenarios requiring executable code. It is primarily used for data representation.
const data = {a: 'apple', b: 'banana'}; console.log(JSON.stringify(data, ['a']));
a) `{"a":"apple"}` b) `{a: "apple"}` c) `{"a":"apple","b":"banana"}` d) `{}` ## Answer: a Rationale: The second parameter of `JSON.stringify()` allows for a whitelist of properties to include in the JSON string. 17. Which statement is true about deeply nested JSON objects and circular references in JavaScript? a) They can always be serialized with JSON.stringify(). b) They cannot be serialized at all. c) They can be handled using a replacer function in JSON.stringify(). d) They automatically resolve during serialization. ## Answer: c Rationale: The `JSON.stringify()` method can take a `replacer` function to handle and potentially omit circular references. ### Fill-in-the-Blank (Advanced) B) text/json C) application/x-json D) text/javascript ## Correct Answer: A) application/json Rationale: The official MIME type for JSON is application/json, which is necessary for proper JSON data interchange. 2. True/False: JSON keys can be non-string data types. ## Correct Answer: False Rationale: In JSON, keys must always be strings enclosed in double quotes. 3. Fill-in-the-blank: In JSON, the _______ data type is used to store simple values like strings, numbers, and Booleans. ## Correct Answer: scalar Rationale: Scalar data types in JSON are used to represent simple data types that are not objects or arrays. 4. Multiple Choice: Which of the following is not a valid JSON value? A) "Hello, World!" B) null C) undefined D) 42 ## Correct Answer: C) undefined Rationale: undefined is not a valid JSON value; JSON only supports null for representing non-values. 5. True/False: JSON supports comments within the data format. ## Correct Answer: False Rationale: JSON does not support comments. Adding comments to a JSON file will invalidate the JSON format. 6. Fill-in-the-blank: To ensure a JSON file is properly formatted, it should be validated against a _______. ## Correct Answer: schema Rationale: A JSON schema defines the structure and rules for a JSON file, ensuring it is correctly formatted. 7. Multiple Choice: What does JSONP stand for? A) JSON Parsing B) JSON Programming C) JSON with Padding D) JSON Printing ## Correct Answer: C) JSON with Padding Rationale: JSONP (JSON with Padding) is a method used to request data from a server residing in a different domain than the client. Rationale: A single string, when properly quoted, is a valid JSON text. 12. Fill-in-the-blank: The process of converting a JavaScript object into a JSON string is known as _______. ## Correct Answer: serialization Rationale: Serialization is the process of converting an object into a format that can be easily shared or stored, such as a JSON string. 13. Multiple Choice: Which of the following characters must be escaped in JSON strings? A)! B) $ C) " D) % ## Correct Answer: C) " Rationale: In JSON, certain characters like the double quote must be escaped to be correctly represented within strings. 14. True/False: JSON can represent date/time data directly as a data type. ## Correct Answer: False Rationale: JSON does not have a date/time data type. Dates are usually represented as strings or numbers in JSON. 15. Fill-in-the-blank: A common use of JSON is to transmit data between a server and a web _______. ## Correct Answer: application Rationale: JSON is widely used for transmitting data between a server and a web application as part of the AJAX technology stack. Multiple Choice: a. What does JSON stand for? A. JavaScript Object Notation B. Java Symbolic Object Notation C. JavaScript Object Navigation D. Java Syntax Object Notation ## Correct Answer: A. JavaScript Object Notation Rationale: JSON stands for JavaScript Object Notation and is a lightweight data interchange format inspired by JavaScript object literal syntax. Fill-in-the-Blank: a. In JSON, data is stored in key-value pairs enclosed in __. ## Correct Answer: curly braces {} Fill-in-the-Blank: a. To represent an array in JSON, the values are enclosed in __. ## Correct Answer: square brackets [] Rationale: Arrays in JSON are represented by enclosing the values in square brackets []. True/False: a. JSON supports nested objects. ## Correct Answer: True Rationale: JSON allows for nested objects where objects can contain other objects as values. Multiple Choice: a. Which method is used to convert a JSON string to a JavaScript object? A. JSON.parse() B. JSON.stringify() C. JSON.convert() D. JSON.object() ## Correct Answer: A. JSON.parse() Rationale: JSON.parse() is used to parse a JSON string and convert it into a JavaScript object. Fill-in-the-Blank: a. JSON data is often transferred between a server and a client using __. ## Correct Answer: HTTP requests Rationale: JSON data is commonly transferred between a server and a client using HTTP requests. True/False: a. JSON supports comments like JavaScript. ## Correct Answer: False Rationale: JSON does not support comments, unlike JavaScript. Multiple Choice: a. Which character is used to separate key and value in a JSON object? Rationale: JSON does not have built-in support for data types such as date and time. Multiple Choice: a. Which method is used to convert a JavaScript object to a JSON string? A. JSON.stringify() B. JSON.objectify() C. JSON.convertToString() D. JSON.string() ## Correct Answer: A. JSON.stringify() Rationale: JSON.stringify() is used to convert a JavaScript object to a JSON string. Fill-in-the-Blank: a. JSON arrays can contain __. ## Correct Answer: a mix of data types Rationale: JSON arrays can contain a mix of data types including strings, numbers, objects, and arrays. True/False: a. JSON is human-readable and easy to write. ## Correct Answer: True Rationale: JSON is designed to be human-readable and easy to write, making it popular for data interchange.