Schema
Question and Answer Schema API with JSON-LD
On this page
Implementation overview
Use defineQuestion() to connect a question with its accepted answer in JSON-LD. This reference covers required values, generated identifiers, WebPage relationships, aliases, and complete TypeScript examples.
Schema.org Question
- Type:
defineQuestion<T extends Record<string, any>>(input?: Question & T)
Describes an individual question. It is commonly used on anFAQPage.
Useful Links
Question and answer properties
- name
stringor questionstring
The text content of the question. - acceptedAnswer
string | Answeror answerstring
The text content of the answer.
Examples
Minimal
defineQuestion({
name: 'What is the meaning of life?',
acceptedAnswer: '42',
})
Defaults
- @type:
Question - @id:
${canonicalUrl}#/schema/question/{n} - inLanguage:
inLanguagefrom resolved page metadata (see: Schema.org Params)
Resolves
See Global Resolves for full context.
- converts the
questionalias tonameand theansweralias toacceptedAnswer - converts a string answer to an Answer object
- assigns numbered IDs in registration order when
@idis not provided - serializes
dateCreatedDate objects as ISO 8601 strings
Relation Transforms
- Each question appends an entry to
mainEntitywhen the WebPage includes theFAQPagetype
Types
/**
* A specific question, e.g., from a user seeking answers online or collected in a Frequently Asked Questions (FAQ) document.
*/
export interface QuestionSimple extends Thing {
/**
* The text content of the question.
*/
name?: string
/**
* An answer object, with a text property which contains the answer to the question.
*/
acceptedAnswer?: NodeRelation<Answer | string>
/**
* The language code for the question; e.g., en-GB.
*/
inLanguage?: string
/**
* The number of answers provided for this question.
*/
answerCount?: number
/**
* The date and time the question was created.
*/
dateCreated?: ResolvableDate
/**
* Alias for `name`
*/
question?: string
/**
* Alias for `acceptedAnswer`
*/
answer?: string
}
/**
* An answer offered to a question; perhaps correct, perhaps opinionated or wrong.
*/
export interface AnswerSimple extends Thing {
text: string
}
export interface Answer extends AnswerSimple {}
Related Schemas
Did this page help you?