HTML & Json comparison

Author

Muhammad Imran

Working with HTML, JSON, and Multi-Format Data Structures in R

This document provides a complete, structured methodology for approaching assignments involving multi-format data integration (specifically HTML and JSON), hosting files on GitHub, reading remote data directly into R, and performing comparative structural analyses. it also induces the code and probable results.

1. Conceptual Framework & Objectives

When completing tasks that require cross-format data ingestion, the primary goal is to understand how different file formats store relational data, how web protocols (like raw GitHub links) serve these assets, and how programming languages parse them into consistent rectangular data structures (data frames).

Key Learning Objectives:

  • Data Structuring & Serialization: Designing clean, standardized datasets in both markup (HTML) and structured hierarchical (JSON) formats.

  • Remote Version Control Integration: Hosting raw data assets on GitHub and accessing them programmatically using direct raw URLs (raw.githubusercontent.com).

  • Multi-Format Ingestion in R: Utilizing domain-specific packages (rvest for HTML parsing and jsonlite for JSON parsing) to ingest remote text.

  • Table Rendering: Presenting data cleanly using formatting packages.

  • Comparative Validation: Assessing structural identity, type coercion differences, and schema variations between different file formats holding identical semantic information.

2. Step-by-Step Execution Workflow

STEP 1: DATA DESIGN & MODELING: I have chosen three books i.e. A Brief History of Time, The Grand Design and Astrophysics for People in a Hurry and find out their authors, publication year, publisher and genre.

STEP 2: FILE CREATION & FORMATTING: Thereafter, building an HTML file featuring structured table elements and likewise building a JSON file utilizing nested objects and arrays.

STEP 3: REMOTE HOSTING & RAW LINK RESOLUTION: Ipushed files to a public GitHub of my account and obtained obtained the raw asset URL (raw.githubusercontent.com) to bypass UI wrapper HTML.

STEP 4: R INGESTION & PARSING PIPELINE: Following sub-steps are taken under this step:

  • Ingest HTML via `rvest::read_html()` and extract nodes with `html_table()`

  • Ingest JSON via `jsonlite::fromJSON()` into lists and data frames

STEP 5: VISUALIZATION & COMPARATIVE ANALYSIS: Following sub-steps are taken under this step:

  • Render formatted tables using `knitr::kable()` and `kableExtra`

  • Execute structural checks (`identical()`, `all.equal()`) to evaluate parity

=== Table from HTML File ===
Books Data Extracted from GitHub HTML File
Title Authors Publication Year Publisher Genre
A Brief History of Time Stephen Hawking 1988 Bantam Books Cosmology / Popular Science
The Grand Design Stephen Hawking and Leonard Mlodinow 2010 Bantam Books Physics / Philosophy of Science
Astrophysics for People in a Hurry Neil deGrasse Tyson 2017 W. W. Norton & Company Astrophysics / Popular Science

=== Table from JSON File ===
Books Data Extracted from GitHub JSON File
Title Authors Publication Year Publisher Genre
A Brief History of Time Stephen Hawking 1988 Bantam Books Cosmology / Popular Science
The Grand Design Stephen Hawking and Leonard Mlodinow 2010 Bantam Books Physics / Philosophy of Science
Astrophysics for People in a Hurry Neil deGrasse Tyson 2017 W. W. Norton & Company Astrophysics / Popular Science
[1] FALSE
[1] "Names: 5 string mismatches"                                                            
[2] "Attributes: < Component \"class\": Lengths (3, 1) differ (string compare on first 1) >"
[3] "Attributes: < Component \"class\": 1 string mismatch >"                                

Comparison Analysis: Similarities and Differences

1. Are they identical?

No, they are not strictly identical. While they contain the exact same core information about the books, their data structures and underlying types have minor differences due to how HTML tables are parsed versus how JSON objects are structured.

2. Similarities

  • Content and Values: Both data frames represent the exact same three books (Stephen Hawking’s and Neil deGrasse Tyson’s works) and hold identical text values for titles, publishers, and genres.

  • Dimensions: Both data frames share the same dimensions—3 rows and 5 columns.

  • Column Representation: Both tables cover the same attributes: Title, Authors, Publication Year, Publisher, and Genre.