File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33require 'json'
44
55module JWT
6- # JSON parsing utilities with duplicate key detection support
76 # @api private
87 class JSON
98 class << self
10- # Generates a JSON string from the given data
11- # @param data [Object] the data to serialize
12- # @return [String] the JSON string
139 def generate ( data )
1410 ::JSON . generate ( data )
1511 end
1612
17- # Parses a JSON string with optional duplicate key detection
18- #
19- # @param data [String] the JSON string to parse
20- # @param allow_duplicate_keys [Boolean] whether to allow duplicate keys (default: true)
21- # @return [Hash] the parsed JSON object
22- # @raise [JWT::DuplicateKeyError] if allow_duplicate_keys is false and duplicate keys are found
23- #
24- # @example Default behavior (allows duplicates, uses last value)
25- # JWT::JSON.parse('{"a":1,"a":2}') # => {"a" => 2}
26- #
27- # @example Strict mode (rejects duplicates)
28- # JWT::JSON.parse('{"a":1,"a":2}', allow_duplicate_keys: false)
29- # # => raises JWT::DuplicateKeyError
3013 def parse ( data , allow_duplicate_keys : true )
3114 return ::JSON . parse ( data ) if allow_duplicate_keys
3215
You can’t perform that action at this time.
0 commit comments