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
-
Hello @sinclairzx81 , I am using type box to define schemas but will need to use it across typescript and also Python projects, so the raw JSON schema will be necessary. Does this library have anything that allows us to extract the JSON string from typebox objects? E.g |
Beta Was this translation helpful? Give feedback.
Answered by
sinclairzx81
Oct 26, 2022
Replies: 2 comments
-
@lucashfreitas Hey Lucas ! :) TypeBox types are JSON Schema objects, So you can just 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! |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
lucashfreitas
-
Oh, so easy! :) Thank you! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@lucashfreitas Hey Lucas ! :)
TypeBox types are JSON Schema objects, So you can just
console.log()
them to print them out. For example.Hope that helps!
S