Just another boring article about JSON? Not really. First off, ur homework is to google JSON to see what it stands for then I’ll tell u the rest below. I am deliberately skipping all the definitional jargon because I think this jargon is what makes the topic seem boring.
Hmmm.. how can i make a boring topic sound palatable and appetizing? JSON, the defacto data format for HTML, end of story. Not exactly folks. I can find 3 real exciting talking points for JSON. Fun for everyone.
First, everyone wants a bargain. We actually save money by storing our data as a JSON file.
Next, Serverless? Hell yeah! JSON in the AWS cloud, with only a few easy steps in plain JS (no node necessary).
Finally, faster data with noSQL. Who would say no to faster. Caveat, some limitations do apply to this format.
So how can u beat these 3 reasons to appreciate JSON. Have I convinced u yet?
Now lets elaborate on these 3 features. Oh, and don't miss out on part 2 of this piece, storing JSON in an AWS s3 bucket.
1. money saving - I'm only paying 5 cents per month to AWS now after paying $10+ per month hosting servers on EC2 for the past 2 years. This is badass! Could of done it sooner but I had to work for a living. Now that time is on my side I am able to delve into the world of serverless computing. People should have my problems.
2. thats it ! Serverless, yay! Getting rid of all my server overhead results in dollars saved. I achieved serverless by making an AWS lambda do my CRUD operations on the data. Previously Oracle, MySql and Postgres were my world for 20 years but now I ditched all that. Also, I pay 25 cents per month to outsource my Apache httpd server to host my html. Yes u can use Mongodb or Cockroach or even hybrid Postgres for noSQL but all these apps require a server. So the raw JSON option I write about here is entirely serverless but does require some extra work. Afterall we are programmers aren't we?
4. So what about the Logic Layer. Because we do not utilize a query engine here we need to simulate one. I construct a simple AWS Lambda function for this. In short we insert data into our array and we update the data when certain events occur.
The simplest way to store a JSON file is in AWS s3. By not creating a schema in a traditional data server we become serverless. We are out in the AWS cloud with s3 where we can connect to our bucket from anywhere. As said previously the noSQL s3 approach has some limitations. But it also has big benefits. When working with data, human nature tends to want to only use one table similar to the ole days where we relied heavily on one excel table. This one flat file format can handle a few metrics so we don’t bombard our audience with complexity. An ideal use case for a flat file is a simple dashboard.
First we create an AWS s3 bucket then we upload the JSON file. Here is how we do it:
2. make it public, by going to bucket permissions tab to turn off block public access - go to block public access section, edit, uncheck and save
3. stay in permissions tab then edit bucket policy, erase what is there and replace with following, then save changes (remember to replace your bucket name below with the actual name)
"Resource": "arn:aws:s3:::your bucket name/*"
4. then, still in permissions tab go to cross origin (cors), edit and replace with below and save
5. Go back to the objects tab and press Upload, then go to where u saved ur newly created JSON file and complete this operation. See this simple example on how to create a JSON file
Note that the above instructions only get u started with JSON in S3. If u want to manipulate the data u need an AWS Lambda Function, an API gateway and IAM permissions. This will be covered in a separate piece which is a bit more advanced.
Thanks for reading Folks !!
For more about Web Development, SQL and Javago back to my Home Page