@@ -444,14 +444,21 @@ pub unsafe extern "C-unwind" fn kcl_value_plan_to_json(
444444) -> * mut kcl_value_ref_t {
445445 let p = unsafe { ptr_as_ref ( p) } ;
446446 let ctx: & mut Context = unsafe { mut_ptr_as_ref ( ctx) } ;
447- let value = match ctx. buffer . custom_manifests_output . clone ( ) {
448- Some ( output) => ValueRef :: from_yaml_stream ( ctx, & output) . unwrap ( ) ,
449- None => p. clone ( ) ,
450- } ;
451- let ( json_string, yaml_string) = value. plan ( ctx) ;
452- ctx. json_result = json_string. clone ( ) ;
453- ctx. yaml_result = yaml_string. clone ( ) ;
454- new_mut_ptr ( ctx, ValueRef :: str ( & json_string) )
447+ // If custom_manifests_output is set (e.g., from yaml_stream), use it directly for YAML
448+ // For JSON, parse the YAML stream and format as JSON stream
449+ if let Some ( output) = ctx. buffer . custom_manifests_output . take ( ) {
450+ ctx. yaml_result = output. clone ( ) ;
451+ let yaml_result = ctx. yaml_result . clone ( ) ;
452+ let value = ValueRef :: from_yaml_stream ( ctx, & yaml_result) . unwrap ( ) ;
453+ let ( json_string, _) = value. plan ( ctx) ;
454+ ctx. json_result = json_string. clone ( ) ;
455+ new_mut_ptr ( ctx, ValueRef :: str ( & ctx. json_result ) )
456+ } else {
457+ let ( json_string, yaml_string) = p. plan ( ctx) ;
458+ ctx. json_result = json_string. clone ( ) ;
459+ ctx. yaml_result = yaml_string. clone ( ) ;
460+ new_mut_ptr ( ctx, ValueRef :: str ( & ctx. json_result ) )
461+ }
455462}
456463
457464#[ unsafe( no_mangle) ]
@@ -461,14 +468,21 @@ pub unsafe extern "C-unwind" fn kcl_value_plan_to_yaml(
461468) -> * mut kcl_value_ref_t {
462469 let p = unsafe { ptr_as_ref ( p) } ;
463470 let ctx = unsafe { mut_ptr_as_ref ( ctx) } ;
464- let value = match ctx. buffer . custom_manifests_output . clone ( ) {
465- Some ( output) => ValueRef :: from_yaml_stream ( ctx, & output) . unwrap ( ) ,
466- None => p. clone ( ) ,
467- } ;
468- let ( json_string, yaml_string) = value. plan ( ctx) ;
469- ctx. json_result = json_string. clone ( ) ;
470- ctx. yaml_result = yaml_string. clone ( ) ;
471- new_mut_ptr ( ctx, ValueRef :: str ( & yaml_string) )
471+ // If custom_manifests_output is set (e.g., from yaml_stream), use it directly
472+ if let Some ( output) = ctx. buffer . custom_manifests_output . take ( ) {
473+ ctx. yaml_result = output. clone ( ) ;
474+ // For JSON, we still need to parse and format the YAML stream
475+ let yaml_str = ctx. yaml_result . clone ( ) ;
476+ let value = ValueRef :: from_yaml_stream ( ctx, & yaml_str) . unwrap ( ) ;
477+ let ( json_string, _) = value. plan ( ctx) ;
478+ ctx. json_result = json_string;
479+ new_mut_ptr ( ctx, ValueRef :: str ( & ctx. yaml_result ) )
480+ } else {
481+ let ( json_string, yaml_string) = p. plan ( ctx) ;
482+ ctx. json_result = json_string. clone ( ) ;
483+ ctx. yaml_result = yaml_string. clone ( ) ;
484+ new_mut_ptr ( ctx, ValueRef :: str ( & yaml_string) )
485+ }
472486}
473487
474488#[ unsafe( no_mangle) ]
0 commit comments