@@ -173,6 +173,7 @@ def validate(
173173 typer .Option (help = "The project name." ),
174174 ] = None ,
175175 strict : bool = typer .Option (False , "--strict" , help = "Exit with error on validation failures" ),
176+ json_output : bool = typer .Option (False , "--json" , help = "Output in JSON format" ),
176177 local : bool = typer .Option (
177178 False , "--local" , help = "Force local API routing (ignore cloud mode)"
178179 ),
@@ -183,6 +184,7 @@ def validate(
183184 TARGET can be a note path (e.g., people/ada-lovelace.md) or a note type
184185 (e.g., person). If omitted, validates all notes that have schemas.
185186
187+ Use --json for machine-readable output.
186188 Use --strict to exit with error code 1 if any validation errors are found.
187189 Use --local to force local routing when cloud mode is enabled.
188190 Use --cloud to force cloud routing when cloud mode is disabled.
@@ -211,12 +213,19 @@ def validate(
211213
212214 # Handle error responses
213215 if isinstance (result , dict ) and "error" in result :
214- console .print (f"[yellow]{ result ['error' ]} [/yellow]" )
216+ if json_output :
217+ print (json .dumps (result , indent = 2 , default = str ))
218+ else :
219+ console .print (f"[yellow]{ result ['error' ]} [/yellow]" )
215220 return
216221
217222 # output_format="json" guarantees a dict return
218223 assert isinstance (result , dict )
219- _render_validate_table (result )
224+
225+ if json_output :
226+ print (json .dumps (result , indent = 2 , default = str ))
227+ else :
228+ _render_validate_table (result )
220229
221230 if strict and result .get ("error_count" , 0 ) > 0 :
222231 raise typer .Exit (1 )
@@ -245,6 +254,7 @@ def infer(
245254 0.25 , "--threshold" , help = "Minimum frequency for optional fields (0-1)"
246255 ),
247256 save : bool = typer .Option (False , "--save" , help = "Save inferred schema to schema/ directory" ),
257+ json_output : bool = typer .Option (False , "--json" , help = "Output in JSON format" ),
248258 local : bool = typer .Option (
249259 False , "--local" , help = "Force local API routing (ignore cloud mode)"
250260 ),
@@ -258,6 +268,7 @@ def infer(
258268 Fields present in 95%+ of notes become required. Fields above the
259269 threshold (default 25%) become optional. Fields below threshold are excluded.
260270
271+ Use --json for machine-readable output.
261272 Use --local to force local routing when cloud mode is enabled.
262273 Use --cloud to force cloud routing when cloud mode is disabled.
263274 """
@@ -277,18 +288,27 @@ def infer(
277288
278289 # Handle error responses
279290 if isinstance (result , dict ) and "error" in result :
280- console .print (f"[yellow]{ result ['error' ]} [/yellow]" )
291+ if json_output :
292+ print (json .dumps (result , indent = 2 , default = str ))
293+ else :
294+ console .print (f"[yellow]{ result ['error' ]} [/yellow]" )
281295 return
282296
283297 # output_format="json" guarantees a dict return
284298 assert isinstance (result , dict )
285299
286300 # Handle zero notes
287301 if result .get ("notes_analyzed" , 0 ) == 0 :
288- console .print (f"[yellow]No notes found with type: { note_type } [/yellow]" )
302+ if json_output :
303+ print (json .dumps (result , indent = 2 , default = str ))
304+ else :
305+ console .print (f"[yellow]No notes found with type: { note_type } [/yellow]" )
289306 return
290307
291- _render_infer_table (result )
308+ if json_output :
309+ print (json .dumps (result , indent = 2 , default = str ))
310+ else :
311+ _render_infer_table (result )
292312
293313 if save :
294314 console .print (
@@ -316,6 +336,7 @@ def diff(
316336 Optional [str ],
317337 typer .Option (help = "The project name." ),
318338 ] = None ,
339+ json_output : bool = typer .Option (False , "--json" , help = "Output in JSON format" ),
319340 local : bool = typer .Option (
320341 False , "--local" , help = "Force local API routing (ignore cloud mode)"
321342 ),
@@ -327,6 +348,7 @@ def diff(
327348 are actually structured. Identifies new fields,
328349 dropped fields, and cardinality changes.
329350
351+ Use --json for machine-readable output.
330352 Use --local to force local routing when cloud mode is enabled.
331353 Use --cloud to force cloud routing when cloud mode is disabled.
332354 """
@@ -345,12 +367,19 @@ def diff(
345367
346368 # Handle error responses
347369 if isinstance (result , dict ) and "error" in result :
348- console .print (f"[yellow]{ result ['error' ]} [/yellow]" )
370+ if json_output :
371+ print (json .dumps (result , indent = 2 , default = str ))
372+ else :
373+ console .print (f"[yellow]{ result ['error' ]} [/yellow]" )
349374 return
350375
351376 # output_format="json" guarantees a dict return
352377 assert isinstance (result , dict )
353- _render_diff_output (result )
378+
379+ if json_output :
380+ print (json .dumps (result , indent = 2 , default = str ))
381+ else :
382+ _render_diff_output (result )
354383 except ValueError as e :
355384 console .print (f"[red]Error: { e } [/red]" )
356385 raise typer .Exit (1 )
0 commit comments