Generating Valid LocalBusiness JSON-LD Without Manually Managing Nested Schema
01:14 05 Jun 2026

I’ve been working with LocalBusiness schema recently and realized how easy it is to make mistakes when manually constructing JSON-LD.

The structure gets complicated fast because of nested objects like:

  • PostalAddress

  • GeoCoordinates

  • OpeningHoursSpecification

  • reviews

  • social profiles

  • service areas

Even small formatting issues can cause Google to ignore parts of the schema.

To simplify things, I built a lightweight Python wrapper around a schema generation API so I could dynamically generate valid LocalBusiness markup from structured data.

Here’s a simplified version:

import requests

def generate_local_business_schema(name, address, phone, coordinates, hours):
    payload = {
        "type": "LocalBusiness",
        "name": name,
        "address": {
            "@type": "PostalAddress",
            "streetAddress": address['street'],
            "addressLocality": address['city'],
            "addressRegion": address['state'],
            "postalCode": address['zip']
        },
        "telephone": phone,
        "geo": {
            "@type": "GeoCoordinates",
            "latitude": coordinates['lat'],
            "longitude": coordinates['lng']
        },
        "openingHoursSpecification": [
            {
                "@type": "OpeningHoursSpecification",
                "dayOfWeek": day,
                "opens": hours[day]['open'],
                "closes": hours[day]['close']
            }
            for day in hours
        ]
    }

    response = requests.post(
        'https://serpspur.com/api/schema-generator',
        json=payload
    )

    return response.json()

Usage example:

schema = generate_local_business_schema(
    name="My Store",
    address={
        "street": "123 Main St",
        "city": "Anytown",
        "state": "CA",
        "zip": "12345"
    },
    phone="+1-555-123-4567",
    coordinates={
        "lat": 34.0522,
        "lng": -118.2437
    },
    hours={
        "Monday": {"open": "09:00", "close": "17:00"},
        "Tuesday": {"open": "09:00", "close": "17:00"}
    }
)

print(schema)

The biggest advantage is consistency.

Instead of hand-editing JSON-LD every time, I can:

  • generate schemas dynamically

  • validate formatting automatically

  • reuse the same logic across multiple client sites

  • reduce syntax and nesting errors

I’ve also been testing the generated markup with:
https://serpspur.com/tool/schema-markup-generator-json-ld/

It’s useful for checking whether Google will properly recognize the structure before deployment.

Curious how others here handle structured data generation for local SEO:

  • hand-written templates?

  • CMS plugins?

  • server-side generation?

  • schema libraries?

python