LINKEDIN PROFILE API

How to Parse LinkedIn Profile API Responses in JavaScript

Parse LinkedIn profile API JSON in JavaScript and TypeScript: full types, null and empty-list handling, year vs year-month dates, current role and flat rows.

By Surender Kumar, GTM Engineer, ProfileHunt · Published · 8 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 LinkedIn Profile API Responses in JavaScript

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. After status === "ok", TypeScript knows profile is not null.
  • Use ?. and ??, never in. Keys never go missing; values can be null and 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 no title in 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.

One solid slab beside one split into twelve slices: a year-only date and a year-month date

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));

A press flattening nested boxes into one row of equal tiles

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:

ColumnValue
full_nameSatya Nadella
headlineChairman and CEO at Microsoft
locationRedmond, Washington, United States
current_companyMicrosoft
current_titleChairman and CEO
current_since2014-02
latest_schoolThe University of Chicago Booth School of Business
followers12222008
connections500+
last_post_at2026-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

MythReality
"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

  1. Sign in at profilehunt.dev/login: 100 free credits with a work email, 10 with a personal one.
  2. Fetch one profile and save the JSON to a file.
  3. Paste the types above, run toRow on 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.

Get API key 100 free credits with a work email