Tutto Il Web

Main Menu

  • Home
  • Computer networking
  • Web development
  • Web design
  • Internet marketing
  • Web services

Tutto Il Web

Header Banner

Tutto Il Web

  • Home
  • Computer networking
  • Web development
  • Web design
  • Internet marketing
  • Web services
Web development
Home›Web development›What is JSON used for? – JavaScript – SitePoint Forums

What is JSON used for? – JavaScript – SitePoint Forums

By Julie R. Kelsey
April 2, 2022
0
0

fconijn:

Can anyone explain why it would still be interesting to master JSON? Preferably with a concrete example? Thanks in advance.

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"
}

fconijn:

Putting the data in a .php file in php JSON format can solve this problem, but this syntax again makes it quite complicated. Why not use an SQL database then?

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.

Related posts:

  1. Daily Deal: The Modern Web Development and MySQL Programming Pack
  2. What special features of Java are useful in web development?
  3. This training collection explores advanced web development techniques
  4. The 7 Best Websites to Learn Online Web Development

Categories

  • Computer networking
  • Internet marketing
  • Web design
  • Web development
  • Web services

Recent Posts

  • Computer Networking Diploma Guide: Everything You Need to Know
  • Future Web Design and Development
  • Internet marketing agency and consultant, Artisan Internet Marketing, moves from Mount Dora to Sanford, Florida
  • Commission sets goal to eradicate racial disparity in Greenville County | Greenville News
  • Nice article on CSS and Mobile: Alistapart – Community – SitePoint Forums

Archives

  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • February 2020
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • November 2018
  • September 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • June 2017
  • May 2017
  • April 2017
  • February 2017
  • August 2016
  • February 2016
  • November 2015
  • May 2015
  • January 2015
  • October 2014
  • April 2014
  • January 2014
  • September 2013
  • August 2013
  • June 2013
  • May 2013
  • March 2013
  • August 2012
  • Privacy Policy
  • Terms and Conditions