Home
/
JSON Examples
/
Comment thread
Comment thread JSON example
Last updated 2026-05-20
When to use this
Use this for a comment list under a blog post, a moderation tool, or a forum-style view. Each comment carries a postId and a user reference so you can hydrate authors or sort by post.
Example JSON
Comments tied to post 1, as returned by /comments?postId=1 (paginated).
{
"comments": [
{
"id": 1,
"body": "This is some awesome thinking!",
"postId": 1,
"likes": 3,
"user": {
"id": 121,
"username": "emilys",
"fullName": "Emily Johnson"
}
},
{
"id": 2,
"body": "What terrific math help service!",
"postId": 1,
"likes": 14,
"user": {
"id": 92,
"username": "sophiab",
"fullName": "Sophia Brown"
}
},
{
"id": 3,
"body": "I want to learn more.",
"postId": 1,
"likes": 1,
"user": {
"id": 31,
"username": "jamesd",
"fullName": "James Davis"
}
}
],
"total": 3,
"skip": 0,
"limit": 30
}
Request examples
fetch()
Axios
cURL
React
Copy
fetch('https://jsonexamples.com/posts/1/comments')
.then(res => res.json())
.then(({ comments }) => console.log(comments.length));
Copy
const { data } = await axios.get('https://jsonexamples.com/posts/1/comments');
Copy
curl -s https://jsonexamples.com/posts/1/comments
Copy
function Comments({ postId }) {
const [comments, setComments] = useState([]);
useEffect(() => {
fetch('https://jsonexamples.com/posts/' + postId + '/comments')
.then(r => r.json())
.then(d => setComments(d.comments));
}, [postId]);
return <ul>{comments.map(c => <li key={c.id}><b>{c.user.username}</b> {c.body}</li>)}</ul>;
}
Try the live endpoint
Click below to call /posts/1/comments from your browser.
Call /posts/1/comments
// click the button to populate this block
Common variations
Single comment
{
"id": 1,
"body": "This is some awesome thinking!",
"postId": 1,
"likes": 3,
"user": {
"id": 121,
"username": "emilys",
"fullName": "Emily Johnson"
}
}
Empty thread
Shape returned when a post has no comments yet.
{
"comments": [],
"total": 0,
"skip": 0,
"limit": 30
}
Convert this JSON
Generated starting points for TypeScript, JSON Schema, and Zod. Refine before shipping to production.
TypeScript
JSON Schema
Zod
Copy
export interface CommentThread {
"comments": {
"id": number;
"body": string;
"postId": number;
"likes": number;
"user": {
"id": number;
"username": string;
"fullName": string;
};
}[];
"total": number;
"skip": number;
"limit": number;
}
Copy
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "CommentThread",
"type": "object",
"properties": {
"comments": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"body": {
"type": "string"
},
"postId": {
"type": "integer"
},
"likes": {
"type": "integer"
},
"user": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"username": {
"type": "string"
},
"fullName": {
"type": "string"
}
},
"required": [
"id",
"username",
"fullName"
],
"additionalProperties": false
}
},
"required": [
"id",
"body",
"postId",
"likes",
"user"
],
"additionalProperties": false
}
},
"total": {
"type": "integer"
},
"skip": {
"type": "integer"
},
"limit": {
"type": "integer"
}
},
"required": [
"comments",
"total",
"skip",
"limit"
],
"additionalProperties": false
}
Copy
import { z } from 'zod';
export const CommentThreadSchema = z.object({
comments: z.array(z.object({
id: z.number(),
body: z.string(),
postId: z.number(),
likes: z.number(),
user: z.object({
id: z.number(),
username: z.string(),
fullName: z.string()
})
})),
total: z.number(),
skip: z.number(),
limit: z.number()
});
export type CommentThread = z.infer<typeof CommentThreadSchema>;
Copy link to this example
https://jsonexamples.com/json-examples/comment-thread