# Techniques for parsing strings (and more JSON)

**URL:** <https://ziggit.dev/t/techniques-for-parsing-strings-and-more-json/1563>\
**Category:** Brainstorming\
**Tags:** language, memory-management, c, standard-library\
**Created:** [August 23, 2023, 9:15pm UTC](https://ziggit.dev/t/techniques-for-parsing-strings-and-more-json/1563 "2023-08-23T21:15:11Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![squeek502](https://ziggit.dev/user_avatar/ziggit.dev/squeek502/32/409_2.png) [@squeek502](https://ziggit.dev/u/squeek502)\
**Post date:** [August 23, 2023, 10:11pm UTC](https://ziggit.dev/t/techniques-for-parsing-strings-and-more-json/1563/2 "2023-08-23T22:11:03Z")

</div>

I’m not quite sure what it is you’re trying to show here.

As a tangent, `page_allocator` should probably not be used even for examples unless you have a specific reason to use it. It _only_ allocates in multiples of the page size (usually 4096) regardless of the size you give it. If you ask for 1 byte, it’ll allocate 4096.

For example,

```zig
   var out = std.ArrayList(u8).init(std.heap.page_allocator);
   defer out.deinit();

```

this will allocate `4096` bytes (the page size) on the first `append` call. This is not really what you want.

Hard coding allocators (in your `read` function) is also something you want to avoid. Take the allocator as a parameter instead:

```zig
pub fn read(allocator: std.mem.Allocator, json: *const T, cmd: []const u8) !void {

```

This will allow callers to decide the allocation strategy they want to use, and will make it very simple to use `std.testing.allocator` during tests to get leak checking/double free checking/etc for free.

---

_[View the full topic](https://ziggit.dev/t/techniques-for-parsing-strings-and-more-json/1563)._
