# Rewriting JSONata in Go with AI: The gnata Library and $500K Savings
Reco Lead Data Engineer Nir Barak used the AI assistant Cursor to generate the gnata library—a JSONata implementation in Go—in just seven hours. Token costs came to $400, delivering the company an annual $500,000 savings through ditching Node.js infrastructure and optimizing the rules engine.
The Challenge of Scaling JSONata in Production
JSONata is a declarative language for querying and transforming JSON, widely used in threat detection. The reference JavaScript implementation is incompatible with Reco's Go pipeline. The company ran Node.js clusters on Kubernetes: up to 200 replicas to process JSONata expressions via RPC from Go services. This led to IP address shortages and $300,000 annual infrastructure costs alone.
The migration approach was inspired by a Cloudflare case: using the official test suite from the original implementation. AI generates code in the target language until all tests pass. Reco applied the same 1778 tests from jsonata-js.
Porting and Testing Process
The work took seven hours of real time:
- Cursor analyzed the JSONata spec and tests.
- Generated 13,000 lines of Go code.
- Iteratively fixed failures until full coverage.
Deployment ran in shadow mode: gnata processed traffic in parallel with jsonata-js, logging any discrepancies. Over three days—zero errors across billions of events. The library uncovered inconsistencies in the reference implementation: jsonata-js sometimes violates its own spec.
Source: Habr (https://habr.com/ru/news/1015970/)
Economic Impact and Optimizations
Ditching the Node.js RPC fleet saved $300,000 annually. An additional $200,000 came from refactoring the rules engine: previously it spawned tens of thousands of goroutines to work around JSONata limits; now it works directly with gnata.
Overall, one week for integration, including the shadow period. Barak calls this "surgical refactoring"—AI generation targeted at bottlenecks without a full rebuild.
Performance advantages of gnata:
- Up to 1000x speedup on simple expressions.
- Full compatibility with JSONata tests.
- Open-source code for the community.
Key Takeaways
- gnata: 13k lines of Go code, 1778/1778 tests passed.
- $400 in Cursor token costs vs. $500k annual savings.
- Shadow deployment uncovered bugs in jsonata-js.
- Eliminating 200+ Node.js replicas solved the IP address shortage.
- New phase: AI for targeted refactoring of legacy code.
The gnata library is publicly available, demonstrating the feasibility of porting JS engines to Go with AI. For mid/senior developers, it's a case study in automating migrations while preserving the spec.
— Editorial Team
No comments yet.