To parse a LinkedIn profile API response in JavaScript, type it first, then handle three things explicitly: values that are null, lists that are [], and LinkedIn's two date formats ("2014" and "2014-02"). With ProfileHunt every key is always present, so you never test whether a key exists; you test whether its value is null. This guide gives the full TypeScript types, the helpers for dates and the current role, and a function that flattens a profile into one table row.
The LinkedIn profile API overview explains where the data comes from; this post starts once you have the JSON.
Key takeaways
- Type the response as a union on
status. Afterstatus === "ok", TypeScript knowsprofileis notnull. - Use
?.and??, neverin. Keys never go missing; values can benulland lists can be empty. - Role and school dates are strings, not timestamps.
"2014"and"2014-02"both occur;new Date("2014")invents a January 1st. - The current role is the one with
end_date === null. There can be several, and past roles have notitlein the public view.
TypeScript types for the response
These types follow the profile endpoint reference and the sample responses on the ProfileHunt home page. Paste them into a profilehunt.ts file:
export type Position = {
company: string;
company_url: string | null;
title: string | null; // current roles only
location: string | null;
description: string | null;
start_date: string | null; // "2014" or "2014-02"
end_date: string | null; // null = current role
};
export type School = {
school: string;
school_url: string | null;
start_date: string | null;
end_date: string | null;
};
export type Post = {
url: string;
posted_at: string; // ISO 8601 UTC
text: string | null;
likes: number | null;
};
export type Article = {
url: string;
headline: string | null;
image_url: string | null;
published_at: string; // ISO 8601 UTC
likes: number | null;
};
export type Reaction = {
verb: string; // the kind of reaction, as LinkedIn labels it
reacted_at: string; // ISO 8601 UTC
post_url: string | null;
post_author: string | null; // profile name from the post URL
post_at: string | null;
};
export type Comment = {
verb: string; // "commented on a post" or "replied to a comment"
text: string | null;
age: string; // as LinkedIn shows it: "5h", "3d", "2w", "4mo", "1y"
commented_at: string | null; // approximate: age counted back from scraped_at
post_url: string | null;
post_author: string | null;
post_at: string | null; // exact
};
export type Profile = {
public_id: string;
profile_url: string;
full_name: string | null;
first_name: string | null;
last_name: string | null;
photo_url: string | null;
headline: string | null;
about: string | null;
location: string | null;
country: string | null; // two-letter code, e.g. "US"
experience: Position[];
education: School[];
languages: string[];
followers: number | null;
connections: number | null; // 500 means 500 or more
creator: boolean;
badges: string[];
last_post_at: string | null;
recent_posts: Post[];
recent_articles: Article[];
last_reaction_at: string | null;
recent_reactions: Reaction[];
last_comment_at: string | null; // approximate, like commented_at
recent_comments: Comment[];
last_active_at: string | null; // newest of last_post_at, last_reaction_at, last_comment_at
scraped_at: string; // ISO 8601 UTC
};
export type ProfileResult =
| { status: "ok"; profile: Profile }
| { status: "gone" | "unavailable"; profile: null };
That is every key the API returns. The reaction and comment keys show activity even for people who never post; commented_at is approximate because LinkedIn shows only an age such as 4w, while reacted_at and post_at are exact. The profile reference has a note on each field.
To get a ProfileResult, send the request as shown in calling a LinkedIn profile API from Node.js and cast the parsed body: const result = (await res.json()) as ProfileResult.

Parsing the fields that trip people up
Most bugs in profile parsing come from four places: nulls, dates, the current role, and capped numbers. Each has a short fix.
Nulls and empty lists
A value the profile doesn't show publicly is null; a list with nothing in it is []. So profile.experience.length is always safe, and profile.experience[0] may be undefined.
const name = profile.full_name ?? profile.public_id;
const firstSchool = profile.education[0]?.school ?? null;
const postCount = profile.recent_posts.length;
Don't write if ("headline" in profile). It is always true, so it hides the real question: whether headline is null.
Year vs year-month dates
start_date and end_date on roles and schools are what LinkedIn shows: "2000" for Bill Gates at the Gates Foundation, "2014-02" for Satya Nadella at Microsoft. Parse them into parts instead of a Date:
export function parseYearMonth(d: string | null) {
if (!d) return null;
const [year, month] = d.split("-").map(Number);
return { year, month: month ?? null }; // month is 1-12 or null
}
new Date("2014") returns midnight UTC on January 1, 2014, a precision the profile never claimed. Keep month: null and decide per use case, for example "assume mid-year" for tenure estimates. The timestamps (posted_at, published_at, reacted_at, last_post_at, last_active_at, scraped_at and the rest) are full ISO 8601 strings in UTC, so new Date(value) is correct for those.
Sorting the raw strings works: "2014" < "2014-02" < "2015" in plain string comparison.
The current role
A current role has end_date: null. The public view also only shows a title for current roles; past roles come back with title: null.
export function currentRoles(p: Profile) {
return p.experience.filter(e => e.end_date === null);
}
export const currentRole = (p: Profile) => currentRoles(p)[0] ?? null;
Satya Nadella's sample profile has two current roles: Chairman and CEO at Microsoft since "2014-02", and Member Board Of Trustees at the University of Chicago since "2018". currentRole takes the first, because experience keeps the order the profile lists. If you need "the employer", that is usually right; if you need every affiliation, use currentRoles.
Capped and low numbers
connections is capped: LinkedIn shows logged-out visitors "500+" above 500, so 500 means 500 or more. Display it as "500+". Low numbers are real too: Bill Gates' sample shows connections: 8 next to followers: 40725248. For reach, use followers.
const connectionsLabel = (n: number | null) => (n === null ? "" : n >= 500 ? "500+" : String(n));

Flattening a profile into one table row
Spreadsheets, CSV files and SQL tables want one flat row per person. Pick the columns you need and derive the rest:
export function toRow(p: Profile) {
const role = currentRole(p);
return {
public_id: p.public_id,
full_name: p.full_name ?? "",
headline: p.headline ?? "",
location: p.location ?? "",
country: p.country ?? "",
current_company: role?.company ?? "",
current_title: role?.title ?? "",
current_since: role?.start_date ?? "",
latest_school: p.education[0]?.school ?? "",
followers: p.followers ?? "",
connections: connectionsLabel(p.connections),
last_post_at: p.last_post_at ?? "",
scraped_at: p.scraped_at,
};
}
Run on the Satya Nadella sample, console.table([toRow(profile)]) gives:
| Column | Value |
|---|---|
full_name | Satya Nadella |
headline | Chairman and CEO at Microsoft |
location | Redmond, Washington, United States |
current_company | Microsoft |
current_title | Chairman and CEO |
current_since | 2014-02 |
latest_school | The University of Chicago Booth School of Business |
followers | 12222008 |
connections | 500+ |
last_post_at | 2026-10-12T13:03:00.729Z |
Keep the raw JSON next to the flat row (a jsonb column, or a JSONL file). The row is for reading and filtering; the JSON lets you add a column later without fetching the profile again. For a full list-in, file-out script, see the Node.js enrichment workflow.
What Most Guides Get Wrong
They model every field as optional. Writing headline?: string tells TypeScript the key may be absent, which it never is. headline: string | null is accurate and makes the compiler ask the right question.
They parse every date with new Date(). That turns "2014" into a precise timestamp and makes tenure maths look exact when it isn't.
They take experience[0] as the current job. It is the first role listed, which may have ended. Filter on end_date === null first.
Myth vs Reality
| Myth | Reality |
|---|---|
| "TypeScript types validate the API response." | Types disappear at runtime. as ProfileResult is a promise you make; a runtime check is what enforces it. |
"An empty experience means the person has no job." | It means the public view shows no roles. Many members hide details from logged-out visitors. |
"title: null on an old role is a parsing bug." | The public view has no titles for past roles. null is the correct value. |
"connections: 500 means exactly 500." | It means 500 or more. |
Advanced: Runtime Checks and Generated Types
Hand-written types are fine for one service. Two upgrades help when several services consume the same data.
Generate types from the OpenAPI spec. ProfileHunt publishes its schema at /openapi.json, with Profile, Position, School, Post, Article, Reaction and Comment as named schemas. A generator such as openapi-typescript turns it into types, so a new field shows up in your editor when you regenerate.
Check at the boundary, trust inside. Validate once, where JSON enters your system: in the function that calls the API, or where you read stored JSON back. A guard as small as this catches most surprises:
function isProfileResult(x: any): x is ProfileResult {
return (x?.status === "ok" && typeof x.profile?.public_id === "string")
|| ((x?.status === "gone" || x?.status === "unavailable") && x.profile === null);
}
A schema library such as Zod gives the same check with field-level errors. Either way, everything past the boundary can rely on the types.
Where ProfileHunt Fits
ProfileHunt is a LinkedIn Profile API: public LinkedIn profile URL in, JSON out, with the same keys on every response. That stability is what makes the parsing above short: no key checks, one null convention, one date convention.
It costs one credit per profile found, $0.50 per 1,000 profiles, and nothing for gone or unavailable. It returns the public view only, so there are no emails, no phone numbers, no titles for past roles, and connections is capped at 500.
Getting Started
- Sign in at profilehunt.dev/login: 100 free credits with a work email, 10 with a personal one.
- Fetch one profile and save the JSON to a file.
- Paste the types above, run
toRowon it, and compare with the LinkedIn profile JSON schema. Working in Python instead? See parsing profile JSON with Python.
For what the API is and what it covers, return to the LinkedIn profile API overview.
Frequently asked questions
How do I get someone's current job from LinkedIn profile JSON?
Filter experience for entries with end_date === null. The first one is the role listed first on the profile; there may be more than one current role.
Why is the title null for past jobs in the LinkedIn API response?
LinkedIn's public profile view doesn't show titles for past roles, so ProfileHunt returns title: null for them. The company and dates are still there.
How do I convert LinkedIn dates like "2014-02" to a JavaScript Date?
Split on - into a year and an optional month rather than calling new Date(). If you need a Date, choose the day yourself, for example new Date(Date.UTC(year, (month ?? 1) - 1, 1)), and remember the profile only gave year or year-month.
Are there TypeScript types for the LinkedIn profile API?
You can copy the types in this post, or generate them from ProfileHunt's OpenAPI spec at /openapi.json with a tool such as openapi-typescript.
How do I turn LinkedIn profile JSON into a CSV in JavaScript?
Flatten each profile into one object of strings and numbers (name, headline, current company, followers), then write one line per object, quoting values that contain commas or quotes.


