You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a6e4933
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: doc/basics.md
+18Lines changed: 18 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -168,6 +168,24 @@ And another one:
168
168
cout << "number: " << v << endl;
169
169
```
170
170
171
+
Minifying JSON strings without parsing
172
+
----------------------
173
+
174
+
In some cases, you may have valid JSON strings that you do not wish to parse but that you wish to minify. That is, you wish to remove all unnecessary spaces. We have a fast function for this purpose (`minify_string`). This function does not validate your content, and it does not parse it. Instead, it assumes that your string is valid UTF-8. It is much faster than parsing the string and re-serializing it in minified form. Usage is relatively simple. You must pass an input pointer with a length parameter, as well as an output pointer and an output length parameter (by reference). The output length parameter is not read, but written to. The output pointer should point to a valid memory region that is slightly overallocated (by `simdjson::SIMDJSON_PADDING`) compared to the original string length. The input pointer and input length are read, but not written to.
175
+
176
+
```C++
177
+
// Starts with a valid JSON document as a string.
178
+
// It does not have to be null-terminated.
179
+
constchar * some_string = "[ 1, 2, 3, 4] ";
180
+
size_t length = strlen(some_string);
181
+
// Create a buffer to receive the minified string. Make sure that there is enough room,
182
+
// including some padding (simdjson::SIMDJSON_PADDING).
0 commit comments