justinwoo / purescript-simple-json

A simple Purescript JSON library that uses types automatically
http://purescript-simple-json.readthedocs.io
MIT License
133 stars 45 forks source link

Object key transforms #6

Closed justinwoo closed 6 years ago

justinwoo commented 7 years ago

We should probably have this since the symbol is reflected to grab the value out of the foreign object anyway.

jacereda commented 7 years ago

You mean to read things like uppercase keys?

My solution so far has been to newtype the problematic record and:

derive instance genericFoo :: Generic Foo _
instance readForeignFoo :: ReadForeign Foo where
  readImpl = genericDecode (defaultOptions { fieldTransform=toUpper, unwrapSingleConstructors=true })

What do you have in mind?

justinwoo commented 7 years ago

Yeah, I was thinking that at some level or at a leaf, all the keys would be transformable in some way like that that it might be worthwhile to be able to easily put a record newtype there or something. Don't know for sure though.

justinwoo commented 6 years ago

Eh, probably not needed since you can always "DFSDFDF" for keys