Skip to main content

JSON

JSON.parse converts JSON to an object or array

formatter

fractured json

JSON Schema

a blueprint for what data should look like https://json-schema-faker.js.org/ https://github.com/json-schema-faker/json-schema-faker

<script> element is added to the DOM to create a JSON-P request

A JSONP request is made by dynamically injecting a <script> element into the DOM so the browser treats the requested URL as JavaScript and executes the server-supplied callback, thereby bypassing CORS restrictions that apply to ordinary XHR/fetch calls.

JSON.stringify()

const obj = { a: 1, b: 2, c: 3, d: { e: 4 } };

// '{"a":1,"b":2,"c":3,"d":{"e":4}}'
JSON.stringify(obj);

// {
// "a": 1,
// "b": 2,
// "c": 3,
// "d": {
// "e": 4
// }
// }
JSON.stringify(obj, null, ' ');

// Use 2 spaces when formatting JSON output. Equivalent to the above.
JSON.stringify(obj, null, 2);

JSON Server

The beauty of JSON server: it handles create, reads, updates, and deletes, so it feels totally real.

npm install -D json-server

(few errors)

https://blog.angulartraining.com/fake-your-angular-backend-until-you-make-it-8d145f713e14

https://github.com/TheNickDeveloper/AngularWithJsonServerAPI


JSON-Server Angular Schematics

ng add json-server-schematics

https://github.com/bniedermeyer/json-server-schematics

Start the JSON Server

json-server --watch src/api/db.json
var express = require('express');
var path = require('path');
var events = require('./eventController');

var app = express();
var rootPath = path.normalize(__dirname + '/../');

JSON-Server

npm install -g json-server

# verify the installation was successful
json-server -v

#Getting json-server command line help
json-server -h