Skip to content

How to get a working JSON file with the schema definition out of typebox #267

Answered by sinclairzx81
lucashfreitas asked this question in Q&A
Discussion options

You must be logged in to vote

@lucashfreitas Hey Lucas ! :)

TypeBox types are JSON Schema objects, So you can just console.log() them to print them out. For example.

const T = Type.Object({
  x: Type.Number(),
  y: Type.Number(),
  z: Type.Number(),
})

console.log(JSON.stringify(T, null, 2))

// outputs -> {
//   "type": "object",
//   "properties": {
//     "x": {
//       "type": "number"
//     },
//     "y": {
//       "type": "number"
//     },
//     "z": {
//       "type": "number"
//     }
//   },
//   "required": [
//     "x",
//     "y",
//     "z"
//   ]
// }

Hope that helps!
S

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by lucashfreitas
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants