Skip to content

Conversation

@hhaensel
Copy link
Contributor

In some contexts it would be beneficial to have JSONText constructors for Symbol and JSONText arguments. What do you think about the following defintions?

JSON.JSONText(js::Symbol) = JSONText(String(js))
JSON.JSONText(js::JSONText) = js

I think it doesn't hurt and only adds methods that a user would expect to work as defined.

@codecov
Copy link

codecov bot commented Jan 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.27%. Comparing base (f4fbb5a) to head (cbdc049).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #427      +/-   ##
==========================================
+ Coverage   90.26%   90.27%   +0.01%     
==========================================
  Files           7        7              
  Lines        1366     1368       +2     
==========================================
+ Hits         1233     1235       +2     
  Misses        133      133              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

struct JSONText
value::String
end
JSON.JSONText(js::Symbol) = JSONText(String(js))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definition feels really weird/unnecessary to me (who has valid json as a symbol?). I think I'd prefer to not support for now. I think the other definition is fine.

Copy link
Contributor Author

@hhaensel hhaensel Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've written a Julia to JS expression conversion where I use Symbols to mean js variables, e.g.

julia> @jsexpr(:x^2 + :b * :y + 2)
JSExpr("(((x ** 2) + (b * y)) + 2)")

In this context it comes in very handy to automatically convert Symbols to JSONText.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants