Jump to content

Server-Side Scripting/Internet Data

From Wikiversity

This lesson introduces Internet-based JSON data source processing.

Objectives and Skills

[edit | edit source]

Objectives and skills for this lesson include:

  • Understand Internet data sources
  • Understand JSON concepts
  • Process JSON data sources using server-side scripts

Readings

[edit | edit source]
  1. Wikipedia: JSON
  2. Wikipedia: SPARQL

Multimedia

[edit | edit source]
  1. YouTube: Learn JSON in 10 Minutes
  2. YouTube: Introduction to Node-fetch
  3. YouTube: Introduction to SPARQL

Examples

[edit | edit source]

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

Activities

[edit | edit source]

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 /lesson8. For each activity, use the given Wikidata link as the JSON data source.

  1. Review Wikipedia: 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 Wikipedia: 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 Wikipedia:Richter magnitude scale#Richter magnitudes for magnitude description ranges (Micro, Minor, Light, etc.). Use CSS formatting to color-code the data based on magnitude description.
  3. Review Wikipedia: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 Wikipedia: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

[edit | edit source]

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.[1]
  • 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.[2]
  • JSON has advantages over XML in terms of readability and effects on processing time.[3]

Key Terms

[edit | edit source]

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.[4]
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.[5]
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).[6]
SPARQL
The SPARQL query language for RDF is designed to meet the use cases and requirements identified by the RDF Data Access Working Group.[7]
URL (Uniform Resource Locator)
The address of a given unique resource on the Web.[8]

See Also

[edit | edit source]

References

[edit | edit source]
  1. Wikipedia: JSON
  2. The JavaScript Language: JSON methods, to JSON
  3. Joshi, Vineet. "Why You Should be Using JSON Vs XML". blog.cloud-elements.com. Retrieved 2021-03-16.
  4. https://www.educative.io/blog/what-is-database-query-sql-nosql
  5. https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
  6. JSON.org
  7. https://www.w3.org/TR/rdf-sparql-query/
  8. MDN Web Docs: What is an Array?