How to get a working JSON file with the schema definition out of typebox #267
-
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.
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.
-
Oh, so easy! :) Thank you! |
Beta Was this translation helpful? Give feedback.
@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