What is JSON used for? – JavaScript – SitePoint Forums

When the form below is submitted for an authenticated user, the submission is stored in json format.

https://ng-druid.github.io/native_forms_rebuild_v1/89087abb-326d-4a93-888e-9c597ba81b8e

The json file can be seen here.

https://d12b7acm1cy55s.cloudfront.net/89087abb-326d-4a93-888e-9c597ba81b8e.json

Insight:

{
  "text": "cdsdfsfdsfsd",
  "select": "1",
  "textarea": "dsfs as c as d sa das d as d asd as d asd as d asds.nndsfs as c as d sa das d as d asd as d asd as d asds.nndsfs as c as d sa das d as d asd as d asd as d asds.",
  "radiogroup": "2",
  "slider": "72",
  "toggle": "83",
  "checkbox": "true",
  "datepicker": "2022-03-23T04:00:00.000Z",
  "autocomplete": "3198",
  "nested": {
    "nestedValue": "nested"
  },
  "terms": [
    {
      "humanName": "one",
      "terms": [
        {
          "humanName": "a"
        }
      ]
    },
    {
      "humanName": "two",
      "terms": [
        {
          "humanName": "b"
        }
      ]
    }
  ],
  "id": "89087abb-326d-4a93-888e-9c597ba81b8e"
}

In a traditional database, this would require multiple tables to be stored properly. However, in JSON, relational information such as nested terms and terms can be stored as part of a single document. This eliminates requirement tables.

This is another more traditional example of an ad with attributes stored in json format.

{
  "attributes": [
    {
      "attributes": [],
      "computedValue": "30000",
      "displayName": "Asking Price",
      "intValue": 0,
      "name": "price",
      "type": 0,
      "value": "300,00.00"
    },
    {
      "attributes": [],
      "computedValue": "1",
      "displayName": "Beds",
      "intValue": 0,
      "name": "beds",
      "type": 0,
      "value": "1"
    },
    {
      "attributes": [],
      "computedValue": "2",
      "displayName": "Baths",
      "intValue": 0,
      "name": "baths",
      "type": 0,
      "value": "2"
    },
    {
      "attributes": [],
      "computedValue": "2345",
      "displayName": "Sqft",
      "intValue": 0,
      "name": "sqft",
      "type": 0,
      "value": "2345"
    }
  ],
  "cityDisplay": "Seattle, Washington (98060)",
  "description": "ewrewr ew r ew r ew",
  "featureSets": [],
  "id": "012829c6-a75d-11ea-b84a-064be6bfebb4",
  "images": [
    {
      "id": "40acff11-dc45-46c6-98c3-5608649d10cd",
      "path": "media/40acff11-dc45-46c6-98c3-5608649d10cd.png",
      "weight": 1
    }
  ],
  "location": [
    -121.8034,
    47.4323
  ],
  "profileId": "96677e25-c642-43e2-bd26-1e7305784a80",
  "status": 0,
  "title": "New realestate with photo",
  "typeId": "5665f5f8-5533-4aa1-96f4-b78e02714de0",
  "userId": "e36b42fe-b09c-4514-a519-e178bb52957e"
}

I would say that creating the tables and the MVC application to persist the data is much more complicated than storing the data in natural form as json. Especially if you’re building a modern front-end using an mvvm framework like React, Angular, Vue, etc.

The demo above takes this concept one step further by completely eliminating servers and databases from the tech stack. This is two whole levels eliminated. The entire application just works like a native browser program without a server or database.

In my case, json has become an easy, fast, and cheap way to store persistent data. Additionally, there is a wide range of storages that use json as highly available and scalable alternatives to a traditional database.

The demo above uses a CDN (https://www.cloudflare.com/learning/cdn/what-is-a-cdn/) that can reliably handle around 3,500 concurrent, parallel requests. However, there are other more traditional NoSQL options like MongoDB: https://www.mongodb.com/. The demo above uses aws s3 and cloudfront, but cloudflare explains a CDN better than the aws docs.

For experimentation purposes, you can set up a free Mongo database in the cloud for free: https://www.mongodb.com/atlas/database

If you wanted to try the CDN approach with php, I recommend using Flysystem (https://flysystem.thephpleague.com/docs/) with the s3 adapter (https://flysystem.thephpleague.com/docs/ adapt/aws-s3-v3/).

As seen in flysystem, you can also use Azure BLOB or Google Cloud Storage.

The CDN approach is limited in search capabilities. The MongoDB approach is not. MongoDB offers many of the same features in terms of filtering, aggregating, and searching data as traditional relational databases. In fact, MongoDB offers more features.

In my professional opinion, the best search solution is one dedicated to this purpose. All use JSON for storage and queries. Many of these search solutions are also compatible with SQL queries like open search.

Here is an example request in an open search that uses json for the request body payload.

POST https://search-domain.us-east-1.es.amazonaws.com/classified_panelpages/_search/template

{
  "id": "panelpagelistitems",
  "params": {
    "site": [
      {
        "term": {
          "site.keyword": {
            "value": "ipe"
          }
        }
      }
    ],
    "path": [
      {
        "wildcard": {
          "path.keyword": {
            "value": "*"
          }
        }
      }
    ]
  }
}

All that said, basically any API you use these days will use json. In older projects you will find SOAP or proprietary methods, but modern REST APIs use JSON. However, it is not just for data transfer. JSON can be used everywhere, including storage.

Harry L. Blanchard