Server-Side Scripting/Internet Data

This lesson introduces Internet-based JSON data source processing.

Objectives and Skills
Objectives and skills for this lesson include:
 * Understand Internet data sources
 * Understand JSON concepts
 * Process JSON data sources using server-side scripts

Readings

 * 1)  JSON
 * 2)  SPARQL

Multimedia

 * 1) YouTube: Learn JSON in 10 Minutes
 * 2) YouTube: Introduction to Node-fetch
 * 3) YouTube: Introduction to SPARQL

Examples
JSON data for these examples comes from Wikidata: Countries and Temperatures.


 * /Go/
 * /Node.js (Express)/
 * /PHP/
 * /Python (FastAPI)/
 * /Python (Flask)/

Activities
Complete the following activities using HTML, CSS, and a server-side scripting language. Apply best practices for user interface design and your selected scripting language, including modules, comments, indentations, naming conventions, and constants. Use HTML forms, Internet-based JSON data sources for input, server-side scripts for processing, and HTML elements for output. Use separate functions for each type of processing. Avoid global variables by passing parameters and returning results. Add comments at the top of the code modules and include references to any resources used. Add the completed code to your website as. For each activity, use the given Wikidata link as the JSON data source.
 * 1) Review  Saffir–Simpson scale and Wikidata: Tropical Cyclones and Maximum Sustained Winds. Create an application that reads the JSON data source containing dates, storm names, and maximum sustained winds in kilometers per hour. Build an array of dictionaries to hold the storm data. Display the data sorted by storm intensity in decreasing order. For each storm, display the maximum sustained winds in miles per hour, kilometers per hour, and the Saffir-Simpson scale category for the storm. Use CSS formatting to color-code the data based on storm category, similar to Wikipedia:Template:Saffir-Simpson scale.
 * 2) Review  Moment magnitude scale and Wikidata: Earthquakes and Moment Magnitudes Since 2000 C.E.. Create an application that reads the JSON data source containing dates, earthquake names, and moment magnitudes. Build an array of dictionaries to hold the earthquake data. Display the data sorted by earthquake intensity in decreasing order. For each earthquake, display the earthquake name, moment magnitude, and a magnitude description. See Richter magnitude scale for magnitude description ranges (Micro, Minor, Light, etc.).  Use CSS formatting to color-code the data based on magnitude description.
 * 3) Review Wildfire and Wikidata: Wildfires and Area. Create an application that reads the JSON data source containing dates, wildfires, and area impacted. Build an array of dictionaries to hold the wildfire data. Display the wildfire information in decreasing order of impact. Use CSS formatting to color-code the data based on the order of magnitude of area impacted (1, 10, 100, 1,000, etc.).
 * 4) Review Tsunami and Wikidata: Tsunamis by Date. Create an application that reads the JSON data source containing dates, tsunamis, continents, and countries. Build an array of dictionaries to hold the tsunami data. Display the tsunami information in alphabetical order by continent and country. Use CSS formatting to color-code the data based on continent.

Lesson Summary
Additional items may be contributed by course participants
 * JSON is based on a subset of JavaScript and is commonly used with JavaScript, but it is a language-independent format. Most modern programming languages have code for parsing and generating JSON data.
 * In Javascript, the JSON.stringify method is used to convert objects into JSON and the JSON.parse method is used to convert JSON back into an object.
 * JSON has advantages over XML in terms of readability and effects on processing time.

Key Terms
Additional items may be contributed by course participants


 * database query
 * A database query is a request to access data from a database to manipulate it or retrieve it.


 * fetch
 * The fetch method takes one mandatory argument, the path to the resource you want to fetch. It returns a Promise that resolves to the Response to that request, whether it is successful or not.


 * JSON (JavaScript Object Notation)
 * A lightweight data-interchange format, built on two structures. A collection of name/value (dictionary) pairs and an ordered list of values (array).


 * SPARQL
 * The SPARQL query language for RDF is designed to meet the use cases and requirements identified by the RDF Data Access Working Group.


 * URL (Uniform Resource Locator)
 * The address of a given unique resource on the Web.