Home / Companies / Wundergraph / Blog / Post Details
Content Deep Dive

Introducing astjson: Transform and Merge JSON Objects with Unmatched Speed in Go

Blog post from Wundergraph

Post Details
Company
Date Published
Author
Jens Neuse
Word Count
1,744
Language
English
Hacker News Points
2
Summary

The `astjson` package is a Go library that allows for efficient transformation and merging of JSON objects by parsing them into an Abstract Syntax Tree (AST) exactly once, then modifying the AST as needed without touching the actual JSON content. This approach eliminates the need to parse and merge JSON objects repeatedly, reducing CPU time and memory usage. The package simplifies non-null error bubbling in GraphQL responses by walking through both the GraphQL AST and the JSON AST in parallel and "deleting" fields that are not present in the GraphQL AST. Benchmarks show significant improvements in throughput and latency for a GraphQL API Gateway built using this approach, making it an attractive solution for building high-performance APIs.