From 00bab1874ab4fcac91116144f00ce99a7aa5681b Mon Sep 17 00:00:00 2001 From: Chrono Date: Mon, 15 Jan 2024 09:32:32 +0800 Subject: [PATCH] style(tools): simplify the implementation of tools.cjson (#12316) Simplify the implementation of #12019. --- kong/tools/cjson.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/kong/tools/cjson.lua b/kong/tools/cjson.lua index ea668be90178..5ce04e1003e0 100644 --- a/kong/tools/cjson.lua +++ b/kong/tools/cjson.lua @@ -1,21 +1,20 @@ local cjson = require "cjson.safe".new() -local constants = require "kong.constants" +local CJSON_MAX_PRECISION = require "kong.constants".CJSON_MAX_PRECISION + cjson.decode_array_with_array_mt(true) cjson.encode_sparse_array(nil, nil, 2^15) -cjson.encode_number_precision(constants.CJSON_MAX_PRECISION) +cjson.encode_number_precision(CJSON_MAX_PRECISION) + local _M = {} -function _M.encode(json_text) - return cjson.encode(json_text) -end +_M.encode = cjson.encode +_M.decode_with_array_mt = cjson.decode -function _M.decode_with_array_mt(json_text) - return cjson.decode(json_text) -end _M.array_mt = cjson.array_mt + return _M