Skip to content

Commit 0dee9bd

Browse files
committed
Bring back the numerous deprecated alias
This time with explicit deprecation warnings.
1 parent a6949f8 commit 0dee9bd

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

CHANGES.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changes
22

3+
### 2025-04-24 (2.11.1)
4+
5+
* Add back `JSON.restore`, `JSON.unparse`, `JSON.fast_unparse` and `JSON.pretty_unparse`.
6+
These were deprecated 16 years ago, but never emited warnings, only undocumented, so are
7+
still used by a few gems.
8+
39
### 2025-04-24 (2.11.0)
410

511
* Optimize Integer generation to be ~1.8x faster.

lib/json/common.rb

+44
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,50 @@ def dump(obj, anIO = nil, limit = nil, kwargs = nil)
919919
end
920920
end
921921

922+
# :stopdoc:
923+
# All these were meant to be deprecated circa 2009, but were just set as undocumented
924+
# so usage still exist in the wild.
925+
def unparse(...)
926+
if RUBY_VERSION >= "3.0"
927+
warn "JSON.unparse is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1, category: :deprecated
928+
else
929+
warn "JSON.unparse is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1
930+
end
931+
generate(...)
932+
end
933+
module_function :unparse
934+
935+
def fast_unparse(...)
936+
if RUBY_VERSION >= "3.0"
937+
warn "JSON.fast_unparse is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1, category: :deprecated
938+
else
939+
warn "JSON.fast_unparse is deprecated and will be removed in json 3.0.0, just use JSON.generate", uplevel: 1
940+
end
941+
generate(...)
942+
end
943+
module_function :fast_unparse
944+
945+
def pretty_unparse(...)
946+
if RUBY_VERSION >= "3.0"
947+
warn "JSON.pretty_unparse is deprecated and will be removed in json 3.0.0, just use JSON.pretty_generate", uplevel: 1, category: :deprecated
948+
else
949+
warn "JSON.pretty_unparse is deprecated and will be removed in json 3.0.0, just use JSON.pretty_generate", uplevel: 1
950+
end
951+
pretty_generate(...)
952+
end
953+
module_function :fast_unparse
954+
955+
def restore(...)
956+
if RUBY_VERSION >= "3.0"
957+
warn "JSON.restore is deprecated and will be removed in json 3.0.0, just use JSON.load", uplevel: 1, category: :deprecated
958+
else
959+
warn "JSON.restore is deprecated and will be removed in json 3.0.0, just use JSON.load", uplevel: 1
960+
end
961+
load(...)
962+
end
963+
module_function :restore
964+
# :startdoc:
965+
922966
# JSON::Coder holds a parser and generator configuration.
923967
#
924968
# module MyApp

0 commit comments

Comments
 (0)