json_schemer icon indicating copy to clipboard operation
json_schemer copied to clipboard

Add support for symbolized keys

Open mbykovskyy opened this issue 3 years ago • 2 comments

Currently, parsed JSON with symbolized key fails validation. Please add support for validating JSON with symbolized keys.

mbykovskyy avatar Apr 09 '21 17:04 mbykovskyy

Have you got an example for what this trips up on?

jamietanna avatar Oct 25 '21 10:10 jamietanna

Have you got an example for what this trips up on? @jamietanna

For example, Using activerecord_json_validator and passing a schema with symbolized keys like this : validates :data, presence: false, json: { message: ->(errors) { errors }, schema: { type: :object } } Raise this error : JSONSchemer::InvalidSymbolKey (schemas must use string keys)

But like this validates :data, presence: false, json: { message: ->(errors) { errors }, schema: { "type" => :object } } Works fine

Refs:

  • https://github.com/davishmcclurg/json_schemer/blob/ab5ea07e21633952f5025aaabcfbb37c05c3a74d/lib/json_schemer/schema/base.rb#L49

  • https://github.com/davishmcclurg/json_schemer/issues/9

AhmedKamal20 avatar Jan 08 '22 21:01 AhmedKamal20

Released in 2.0.0. Schema keys are deep-stringified to support symbols.

Note: symbol values are not supported (eg, type: :object above).

davishmcclurg avatar Aug 20 '23 21:08 davishmcclurg