From 4e37941cc459f61c2b1a49b59a01cb38ae9201ed Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Thu, 14 Jan 2021 07:49:25 +0100 Subject: [PATCH] Backend style guide: Document JSON guidelines (#30267) * Backend style guide: Document JSON guidelines Signed-off-by: Arve Knudsen --- contribute/style-guides/backend.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/contribute/style-guides/backend.md b/contribute/style-guides/backend.md index e83f0bd090a..33d976f0fe8 100644 --- a/contribute/style-guides/backend.md +++ b/contribute/style-guides/backend.md @@ -89,3 +89,12 @@ for context. ### Unique columns If a column, or column combination, should be unique, add a corresponding uniqueness constraint through a migration. + +## JSON + +The simplejson package is used a lot throughout the backend codebase, but it's legacy, so if at all possible +avoid using it in new code. Use [json-iterator](https://github.com/json-iterator/go) instead, which is a more performant +drop-in alternative to the standard [encoding/json](https://golang.org/pkg/encoding/json/) package. While encoding/json +is a fine choice, profiling shows that json-iterator may be 3-4 times more efficient for encoding. We haven't profiled +its parsing performance yet, but according to json-iterator's own benchmarks, it appears even more superior in this +department.