Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support writing Inf and NaN values as null, instead of returning an error. #31

Closed
pavelxdd opened this issue Jul 14, 2021 · 1 comment
Closed
Labels
enhancement New feature or request

Comments

@pavelxdd
Copy link
Contributor

Hello, could you add a support of writing Inf and NaN values as null, maybe via a writer flag?

Currently a apply this patch for yyjson in my project to achieve this:

diff --git a/src/yyjson.c b/src/yyjson.c
index 6a571b5..dc973a3 100644
--- a/src/yyjson.c
+++ b/src/yyjson.c
@@ -5635,7 +5635,8 @@ static_noinline u8 *write_f64_raw(u8 *buf, u64 raw, bool allow_nan_and_inf) {
                 return buf + 3;
             }
         } else {
-            return NULL;
+            *(v32 *)&buf[0] = v32_make('n', 'u', 'l', 'l');
+            return buf + 4;
         }
     }
     
@@ -5779,7 +5780,8 @@ static_noinline u8 *write_f64_raw(u8 *buf, u64 raw, bool allow_nan_and_inf) {
                 return buf + 3;
             }
         } else {
-            return NULL;
+            *(v32 *)&buf[0] = v32_make('n', 'u', 'l', 'l');
+            return buf + 4;
         }
     }
 }
@ibireme ibireme added the enhancement New feature or request label Jul 14, 2021
@ibireme
Copy link
Owner

ibireme commented Jul 14, 2021

This feature is really necessary.
Added to the master branch, try this flag: YYJSON_WRITE_INF_AND_NAN_AS_NULL.

@ibireme ibireme closed this as completed Aug 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants