From cbdc0498e893f7beb6c7602de1bc82bed4673e05 Mon Sep 17 00:00:00 2001 From: hhaensel Date: Thu, 22 Jan 2026 14:20:09 +0100 Subject: [PATCH] add JSONText methods for Symbol and JSONText --- src/JSON.jl | 2 ++ test/json.jl | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/JSON.jl b/src/JSON.jl index fcc30e0..046c0ce 100644 --- a/src/JSON.jl +++ b/src/JSON.jl @@ -70,6 +70,8 @@ x = JSON.parse("[1,2,3]", JSONText) struct JSONText value::String end +JSON.JSONText(js::Symbol) = JSONText(String(js)) +JSON.JSONText(js::JSONText) = js include("lazy.jl") include("parse.jl") diff --git a/test/json.jl b/test/json.jl index 8725b43..07d2e06 100644 --- a/test/json.jl +++ b/test/json.jl @@ -107,7 +107,7 @@ end arr[3] = "b" @test JSON.json(arr) == "[\"a\",null,\"b\"]" # test custom struct writing - # defined in the test/struct.jl file + # defined in the test/parse.jl file a = A(1, 2, 3, 4) @test JSON.json(a) == "{\"a\":1,\"b\":2,\"c\":3,\"d\":4}" x = LotsOfFields("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35") @@ -256,6 +256,8 @@ end @test JSON.json(Dict(Point(1, 2) => "hi")) == "{\"1_2\":\"hi\"}" x = JSONText("[1,2,3]") @test JSON.json(x) == "[1,2,3]" + @test JSONText(x) == x + @test x == JSONText(Symbol("[1,2,3]")) @test JSON.json((a=1, b=nothing)) == "{\"a\":1,\"b\":null}" @test JSON.json((a=1, b=nothing); omit_null=true) == "{\"a\":1}" @test JSON.json((a=1, b=nothing); omit_null=false) == "{\"a\":1,\"b\":null}"