LINKEDIN PROFILE API

How to Parse Structured LinkedIn Profile JSON with Python

Parse LinkedIn profile JSON in Python: TypedDict types, null and [] handling, year vs year-month dates, current roles, and flattening experience with pandas.

By Surender Kumar, GTM Engineer, ProfileHunt · Published · 10 min read

Also in: Español · Português (Brasil) · Deutsch · Français · 简体中文 · हिन्दी · العربية · বাংলা · Русский · Bahasa Indonesia · اردو · 日本語 · मराठी · Tiếng Việt · తెలుగు · Hausa · Türkçe · தமிழ் · 한국어

How to Parse Structured LinkedIn Profile JSON with Python

To parse structured LinkedIn profile JSON with Python, read the status first, then treat profile as a dict with a fixed set of keys: describe it with TypedDict, check values for None and lists for [], convert "2014" and "2014-02" dates with a small helper, and flatten the experience list with pandas.json_normalize when you need a table. ProfileHunt returns the same keys for every profile, so one parser handles a CEO with thirty roles and a profile that shows almost nothing.

This guide is only about the parsing. For what a profile API does and why the JSON looks the way it does, start with what a LinkedIn profile API is.

Key takeaways

  • Check the envelope before the profile. profile is None whenever status is gone or unavailable.
  • Keys never go missing. Use profile["headline"] and test for None; .get() hides real bugs.
  • Role dates are partial. "2014" and "2014-02" are not full dates; keep the precision when you convert them.
  • Current role means end_date is None. A profile can have several, so return a list.
  • json_normalize drops people with no roles. Merge the flattened table back onto your profile list.

What you are parsing

The response from POST https://api.profilehunt.dev/v1/profile is an envelope with two keys: status and profile. When status is "ok", profile holds the data. When it is "gone" (no public profile at that URL) or "unavailable" (LinkedIn didn't serve it just then), profile is None and no credit is used.

Inside profile, the keys fall into a few groups:

GroupKeysPython type
Identitypublic_id, profile_url, full_name, first_name, last_name, photo_urlstr, names and photo may be None
Summaryheadline, about, location, countrystr or None
Careerexperience, educationlist[dict], may be []
Signalsfollowers, connections, creator, badges, languagesint or None, bool, list[str]
Activitylast_post_at, recent_posts, recent_articlesISO 8601 str or None, list[dict]
Reactions and commentslast_reaction_at, recent_reactions, last_comment_at, recent_comments, last_active_atISO 8601 str or None, list[dict]
Metadatascraped_atISO 8601 str

The LinkedIn profile JSON schema guide explains each field. Here we turn them into Python values you can trust.

Parse a profile in Python, step by step

The examples use the two real sample responses from the ProfileHunt home page: Bill Gates and Satya Nadella.

Step 1: Read the envelope before the profile

data = res.json()

if data["status"] != "ok":
    # "gone": no public profile. "unavailable": try again later. Neither is charged.
    handle_miss(data["status"])
else:
    profile = data["profile"]

Skipping this check is the most common parsing bug. data["profile"]["full_name"] raises TypeError: 'NoneType' object is not subscriptable on the first profile that isn't found. The Python enrichment example shows the full request around this.

Step 2: Describe the shape with TypedDict

TypedDict gives you editor completion and type checking without changing the data: the dict from res.json() is used as is.

from typing import Literal, TypedDict

class Position(TypedDict):
    company: str
    company_url: str | None
    title: str | None          # set for current roles only
    location: str | None
    description: str | None
    start_date: str | None     # "2014" or "2014-02"
    end_date: str | None       # None for a current role

class School(TypedDict):
    school: str
    school_url: str | None
    start_date: str | None
    end_date: str | None

class Post(TypedDict):
    url: str
    posted_at: str
    text: str | None
    likes: int | None

class Article(TypedDict):
    url: str
    headline: str | None
    image_url: str | None
    published_at: str
    likes: int | None

class Reaction(TypedDict):
    verb: str                  # the kind of reaction, as LinkedIn labels it
    reacted_at: str            # ISO 8601 UTC
    post_url: str | None
    post_author: str | None    # profile name from the post URL
    post_at: str | None

class Comment(TypedDict):
    verb: str                  # "commented on a post" or "replied to a comment"
    text: str | None
    age: str                   # as LinkedIn shows it: "5h", "3d", "2w", "4mo", "1y"
    commented_at: str | None   # approximate: age counted back from scraped_at
    post_url: str | None
    post_author: str | None
    post_at: str | None        # exact

class Profile(TypedDict):
    public_id: str
    profile_url: str
    full_name: str | None
    first_name: str | None
    last_name: str | None
    photo_url: str | None
    headline: str | None
    about: str | None
    location: str | None
    country: str | None
    experience: list[Position]
    education: list[School]
    languages: list[str]
    followers: int | None
    connections: int | None
    creator: bool
    badges: list[str]
    last_post_at: str | None
    recent_posts: list[Post]
    recent_articles: list[Article]
    last_reaction_at: str | None
    recent_reactions: list[Reaction]
    last_comment_at: str | None   # approximate, like commented_at
    recent_comments: list[Comment]
    last_active_at: str | None    # newest of last_post_at, last_reaction_at, last_comment_at
    scraped_at: str

class ProfileResponse(TypedDict):
    status: Literal["ok", "gone", "unavailable"]
    profile: Profile | None

The str | None syntax needs Python 3.10 or later. That is every key the API returns. The OpenAPI file describes the same Profile object, so you can generate these types instead of keeping them by hand.

Step 3: Treat None and [] as data

A None means the profile doesn't show that value to a logged-out visitor. It is not an error. Two rules keep it from leaking into your output:

name = profile["full_name"] or profile["public_id"]   # fallback for display
headline = profile["headline"] or ""                  # empty string for a text column

has_posts = bool(profile["recent_posts"])             # [] is falsy
followers = profile["followers"]                      # keep None; 0 would be a lie

Keep numbers as None rather than 0. A profile with followers: None didn't show a count; a profile with 0 followers is a different fact. And remember that connections stops at 500 in the public view, so 500 means "500 or more".

Step 4: Parse year and year-month dates

Role and school dates are strings as LinkedIn shows them: "2000" for Bill Gates at the Gates Foundation, "2014-02" for Satya Nadella at Microsoft. Convert them to a date and keep the precision next to it:

from datetime import date, datetime

def parse_ym(value: str | None) -> tuple[date | None, str | None]:
    """'2014' -> (date(2014, 1, 1), 'year'); '2014-02' -> (date(2014, 2, 1), 'month')."""
    if value is None:
        return None, None
    if len(value) == 4:
        return date(int(value), 1, 1), "year"
    year, month = value.split("-")
    return date(int(year), int(month), 1), "month"

def parse_ts(value: str | None) -> datetime | None:
    """ISO 8601 in UTC, e.g. '2026-10-11T03:45:31.389Z'."""
    return datetime.fromisoformat(value) if value else None

parse_ts works as written on Python 3.11 and later. On 3.10 and earlier, fromisoformat rejects the trailing Z, so use datetime.fromisoformat(value.replace("Z", "+00:00")).

Profile fields passing through a sorting step that separates empty values from filled ones

Step 5: Pick the current roles

def current_roles(profile: Profile) -> list[Position]:
    return [p for p in profile["experience"] if p["end_date"] is None]

On the sample data this returns three roles for Bill Gates (Gates Foundation, Breakthrough Energy, Microsoft) and two for Satya Nadella (Microsoft and a University of Chicago board seat). The first item is usually the main job, but a function that returns one role would silently drop the rest. Past roles come back with title: None, because the public view shows titles for current roles only.

Flatten experience with pandas json_normalize

pandas.json_normalize turns the nested list into one row per role and copies profile-level keys onto each row with meta:

import pandas as pd

roles = pd.json_normalize(
    profiles,                      # a list of profile dicts
    record_path="experience",
    meta=["public_id", "full_name", "scraped_at"],
)
roles["is_current"] = roles["end_date"].isna()
roles["start_year"] = roles["start_date"].str[:4].astype("Int64")

On the two sample profiles this gives eight rows:

public_idcompanytitlestart_yearis_current
williamhgatesGates FoundationCo-chair2000True
williamhgatesBreakthrough EnergyFounder2015True
williamhgatesMicrosoftCo-founder1975True
satyanadellaMicrosoftChairman and CEO2014True
satyanadellaUniversity of ChicagoMember Board Of Trustees2018True
satyanadellaStarbucksNaN2017False
satyanadellaThe Business Council U.S.NaN2021False
satyanadellaFred HutchNaN2016False

For one row per person, use pd.json_normalize(profiles, max_level=0): scalar keys become columns and the lists stay in object columns. Do the same with record_path="education" or "recent_posts" for those lists.

What Most Guides Get Wrong About Parsing Profile JSON

They use .get() everywhere. profile.get("headline", "") looks defensive, but every key is always present, so .get() only hides typos. profile.get("headlnie") returns the default forever instead of failing on the first run.

They parse dates with strptime("%Y-%m"). That fails on every year-only date, and most role dates in the sample are year-only. A single format string can't handle both shapes.

They take experience[0] as the current job. experience[0] can be a role that ended, and many profiles have more than one current role. Filter on end_date is None.

They assume NaN and None behave the same in pandas. After json_normalize, an all-null column like description holds None while a mixed column like title holds NaN. Test with pd.isna(), never with == None.

Myth vs Reality

MythReality
A missing value means the API call failed.A failed lookup has status other than "ok". A None inside an "ok" profile only means the value isn't shown publicly.
connections: 500 is an exact count.It means 500 or more; the public view caps it. Use followers for reach.
Past roles have titles you can parse.The public view shows titles for current roles only, so past roles have title: None.
json_normalize keeps every person.With record_path, a profile whose experience is [] produces no rows and disappears from the table.
You need pydantic to parse this safely.TypedDict plus a few helpers covers it. Reach for a validation library when you accept untrusted input, not for a stable schema.

One nested record unfolding into a flat grid of rows

Advanced: Typed Models at the Edge, Raw JSON in Storage

Once the basics work, three habits keep a parser stable as your pipeline grows.

Store the raw response, derive everything else. Write the untouched profile dict to a JSON column or a JSONL file keyed by public_id and scraped_at. Your flattened tables are then a function you can re-run. When you decide next quarter that you need education or recent_articles, you rebuild from storage instead of paying to fetch again.

Convert to your own model in one place. If your app wants a Contact dataclass with title, company and started fields, write one function that maps a Profile to it, and use nothing else downstream. Field choices (which current role wins, how to treat year-only dates) then live in one spot.

from dataclasses import dataclass

@dataclass
class Contact:
    public_id: str
    name: str | None
    title: str | None
    company: str | None
    started: date | None
    started_precision: str | None

def to_contact(profile: Profile) -> Contact:
    roles = current_roles(profile)
    main = roles[0] if roles else None
    started, precision = parse_ym(main["start_date"]) if main else (None, None)
    return Contact(
        public_id=profile["public_id"],
        name=profile["full_name"],
        title=main["title"] if main else None,
        company=main["company"] if main else None,
        started=started,
        started_precision=precision,
    )

Join on public_id, not names. People share names; they don't share profile URLs. When you merge the flattened roles table back onto a per-person table, public_id is the key, and a left join from the person table keeps the profiles that have no roles.

Watch for new keys, don't break on them. TypedDict doesn't reject extra keys at runtime, so a new field never crashes your parser. If you want to know when one appears, compare set(profile) with Profile.__annotations__ in a test and log the difference.

Where ProfileHunt Fits

ProfileHunt is a LinkedIn Profile API: a public profile URL in, this JSON out. The schema is the same for every profile, with None and [] where a profile shows nothing, which is what makes a small parser like the one above enough. Each lookup reads the public profile live, and scraped_at tells you exactly when.

It returns the public view only: no emails or phone numbers, no titles for past roles, and connections capped at 500. Pricing is $0.50 per 1,000 profiles found, and profiles that aren't found are not charged.

Getting Started

Create a key with 100 free credits on a work email at sign up, make your first call from the quickstart, and keep the profile endpoint reference open while you write your types. To run this parser over a whole list, the Python workflow for enriching profiles at scale covers batches, polling and checkpoints. For the same parsing in TypeScript, see parsing profile responses in JavaScript. For the bigger picture, see what a LinkedIn profile API is.

Frequently asked questions

How do I convert LinkedIn profile JSON to a pandas DataFrame?

Use pd.json_normalize(profiles, max_level=0) for one row per person, and pd.json_normalize(profiles, record_path="experience", meta=["public_id"]) for one row per role. Join the two on public_id.

Why does my Python code fail with 'NoneType' object is not subscriptable?

You read data["profile"] when the status was gone or unavailable, so profile was None. Check data["status"] == "ok" before reading any profile field.

How do I parse LinkedIn dates like "2014-02" in Python?

Split on the dash: four characters is a year, seven is a year and month. Convert to date(year, month or 1, 1) and store whether it was year-only, as in the parse_ym helper above.

How do I find someone's current job in LinkedIn profile JSON?

Take the entries in experience whose end_date is None. There can be more than one; the first is usually the main role.

Should I use pydantic or TypedDict for LinkedIn profile data?

TypedDict is enough when the data comes from a stable API and you only want type hints. Use pydantic when you need runtime validation or coercion, for example when the JSON comes from a file people edit by hand.

Get API key 100 free credits with a work email