It’s often necessary for applications to validate JSON objects, to ensure that required properties are present and that additional constraints (such as a price never being less than one dollar) are met. These validations are typically performed in the context of JSON Schema. Syntactic vs Semantic Validation When we validate a JSON document without it’s […]
JSON
JSON with JSONPath
One of the biggest strengths of XML is XPath, the query-oriented language to query subsections of an XML document. In the same line, JSONPath is a query language for JSON with features similar to XPath. JSONPath is used for selecting and extracting a JSON document’s property values. To use JSONPath, we will need to include […]
JSON with Ajax
Sending JSON request payload and receiving the JSON response object are very common tasks while dealing with AJAX and remote REST APIs. Making AJAX Requests with XMLHttpRequest To make AJAX requests, we create an instance of the XMLHttpRequest object. The XMLHttpRequest object lets us make asynchronous AJAX calls to the live server. XMLHttpRequest comes with […]
JSON Object
The JSON object data type is a list of name-value pairs surrounded in curly braces. JSON objects are very much like javascript objects. JSON objects are written in key/value pairs. JSON objects are surrounded by curly braces { }. Keys must be strings, and values must be a valid JSON data type (string, number, object, […]
JSON Array
Similar to other programming languages, an Array in JSON is a list of items surrounded in square brackets ([]). Each item in the array is separated by a comma. The array index begins with 0. The square brackets [ ] are used to declare JSON array. JSON array are ordered list of values. JSON array […]
JSON parse()
JSON parse() method, as the name suggests, deserializes a JSON string representation to a JavaScript object. The JSON string is typically received from a remote location (e.g. API response) and needs to be used for modifying the UI in the browser. The parse() method takes the JSON string, as received from API response and converts […]
JSON stringify()
The JSON.stringify() function, as name suggests, converts a JavaScript value to a serialized JSON string. JSON.stringify() can optionally use a replacer function to replace values using custom logic. Method Syntax The syntax of the JSON.stringify() method is: Method Parameters value (required) – The JavaScript object which needs to be converted to a JSON string. replacer […]
JSON Data Types
At the granular level, JSON consist of 6 data types. First four data types (string, number, boolean and null) can be referred as simple data types. Other two data types (object and array) can be referred as complex data types. string number boolean null/empty object array Let’s learn about each data type one by one. […]
JSON Syntax
A JSON document may contain information separated by following separators/token. “:” to separate name from value “,” to separate name-value pairs “{” and “}” for objects “[” and “]” for arrays JSON name-value pairs example Name-value pairs have a colon between them as in “name” : “value”. JSON names are on the left side of […]
JSON vs XML
XML has enjoyed an excellent time for being the only choice for open data interchange. The presence of SOAP APIs as major endpoint applications also contributed to its popularity. Later, when the REST APIs emerged as a less complicated and equally capable alternative of SOAP, people also started talking about other mediums for data interchange […]