Prompt

How do I normalize scraped page data into JSON?

Technology / Cloud Infrastructure2 observationsLast seen Nov 20, 2026

Latest observation

Nov 20, 2026OpenAI APIWeb search: off

A good way to normalize scraped page data into JSON is to separate it into three stages:

  1. Extract raw values from the page
  2. Clean/standardize those values
  3. Map them into a consistent JSON schema

1) Define the JSON shape first

Before scraping, decide what the final JSON should look like.

Example schema:

{
  "title": "",
  "price": 0,
  "currency": "USD",
  "url": "",
  "availability": "",
  "images": [],
  "breadcrumbs": [],
  "specs": {},
  "scraped_at": ""
}

Having a fixed schema makes normalization much easier.


2) Normalize common data types

Web pages often contain messy data. Convert them into predictable types.

Strings

  • Trim whitespace
  • Collapse repeated spaces
  • Remove invisible characters
function normalizeText(value) {
  return String(value || "")
    .replace(/\s+/g, " ")
    .trim();
}

Numbers

Convert currency/price strings to numeric values.

function parsePrice(value) {
  const cleaned = String(value || "")
    .replace(/[^0-9.,-]/g, "")
    .replace(/,/g, "");
  return cleaned ? Number(cleaned) : null;
}

URLs

Resolve relative links to absolute URLs.

function normalizeUrl(url, baseUrl) {
  try {
    return new URL(url, baseUrl).toString();
  } catch {
    return null;
  }
}

Dates

Convert dates into ISO format.

function normalizeDate(value) {
  const d = new Date(value);
  return isNaN(d) ? null : d.toISOString();
}

Booleans

Map textual values to true/false.

function parseBoolean(value) {
  const s = String(value || "").toLowerCase();
  return ["true", "yes", "in stock", "available"].includes(s);
}

3) Clean arrays and objects

Arrays

Remove empty items and normalize each entry.

function normalizeArray(arr, itemFn) {
  return (arr || [])
    .map(itemFn)
    .filter(v => v !== null && v !== undefined && v !== "");
}

Key-value specs

Turn tables or definition lists into an object.

function normalizeSpecs(pairs) {
  const out = {};
  for (const { key, value } of pairs) {
    const k = normalizeText(key).toLowerCase();
    const v = normalizeText(value);
    if (k) out[k] = v;
  }
  return out;
}

4) Build a transformation layer

Create one function that takes raw scraped data and returns normalized JSON.

function normalizeProduct(raw, baseUrl) {
  return {
    title: normalizeText(raw.title),
    price: parsePrice(raw.price),
    currency: normalizeText(raw.currency) || null,
    url: normalizeUrl(raw.url, baseUrl),
    availability: normalizeText(raw.availability).toLowerCase(),
    images: normalizeArray(raw.images, img => normalizeUrl(img, baseUrl)),
    breadcrumbs: normalizeArray(raw.breadcrumbs, normalizeText),
    specs: normalizeSpecs(raw.specs || []),
    scraped_at: new Date().toISOString()
  };
}

Example input:

const raw = {
  title: "  Fancy Shoes  ",
  price: "$129.99",
  currency: "USD",
  url: "/product/123",
  availability: "In Stock",
  images: ["/img1.jpg", " /img2.jpg "],
  breadcrumbs: ["Home", "Shoes", "Sneakers"],
  specs: [
    { key: "Color", value: "Black" },
    { key: "Size", value: "42" }
  ]
};

Output:

{
  "title": "Fancy Shoes",
  "price": 129.99,
  "currency": "USD",
  "url": "https://example.com/product/123",
  "availability": "in stock",
  "images": [
    "https://example.com/img1.jpg",
    "https://example.com/img2.jpg"
  ],
  "breadcrumbs": ["Home", "Shoes", "Sneakers"],
  "specs": {
    "color": "Black",
    "size": "42"
  },
  "scraped_at": "2026-11-20T..."
}

5) Handle missing and inconsistent data

Scraped pages vary a lot, so use rules like:

  • Missing strings → null or ""
  • Missing numbers → null
  • Missing arrays → []
  • Unknown values → keep raw value in a fallback field if needed

Example:

{
  "price": null,
  "price_raw": "Call for price"
}

This is especially useful when some pages don’t fit the expected pattern.


6) Validate the final JSON

After normalization, validate against a schema so bad data doesn’t slip through.

Example with JSON Schema:

  • required fields
  • correct types
  • allowed enums

You can use libraries like:

  • Ajv for JavaScript
  • Pydantic for Python
  • Zod for TypeScript

7) Best practices

  • Keep raw scraped data separate from normalized output
  • Use a single canonical schema
  • Normalize at the edge, before storing or sending data
  • Preserve raw values for debugging
  • Add logging for unexpected formats
  • Make normalization functions reusable and testable

Simple workflow

  1. Scrape raw page data
  2. Extract fields into a raw object
  3. Normalize each field
  4. Validate schema
  5. Store as JSON

If you want, I can also show:

  • a Python example
  • a JavaScript/Node example
  • a JSON Schema for validation
  • or a real scraper pipeline using BeautifulSoup / Cheerio / Playwright

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (2 observations for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.