Skip to main content

Timeline for Format Json Responses as Camel Case

Current License: CC BY-SA 4.0

11 events
when toggle format what by license comment
Jun 20, 2019 at 14:16 comment added The Pax Bisonica I understand that drupal property convetion is snake case, but I'm talking about the JSON response sent to the front end, most languages/frameworks have a very easy to way to convert the payload to camel case and back to snake case, also javascript naming convetions is camel case so which is why we typically use a serializer
Jun 20, 2019 at 13:49 comment added mradcliffe Additionally, working around Drupal properties means that if you take in data you'd need some way to map back into the real properties, which gets complex quickly when dealing with large data sets. That could be alleviated by making leaner services though.
Jun 20, 2019 at 13:47 comment added mradcliffe Drupal convention for properties is to use snake case so if you have a contradictory opinion forcing your hand at API design, then you'll need to redo things (I had to do this in Services in Drupal 7 because someone couldn't handle, opinion-wise, "field_" on properties). I guess, if you're not relying on serialization module, then making your own JsonResponse would be fine. I don't think this is worth it and it would increase the cognitive load for anyone learning the site code base.
Jun 20, 2019 at 13:14 comment added The Pax Bisonica what would you say is the best way to handle that then? We were thinking about extending the JsonResponse class and then having it returned a camel case response
Jun 20, 2019 at 13:06 comment added Kevin Without looking at the code I think JsonResponse ensures the returned HTTP response is proper, but won’t auto convert your data structure the way you want it.
Jun 20, 2019 at 12:50 comment added The Pax Bisonica getMarkets is just returning an array of objects and we aren't formatting it in the service at all, I was wondering if there was a way to format all outgoing responses without doing it manually for every call
Jun 20, 2019 at 2:31 comment added Kevin What is getMarkets returning? Are you using the Serializer service to format it’s response? See: symfony.com/doc/current/serializer.html
Jun 20, 2019 at 1:15 history edited avpaderno
edited tags
Jun 19, 2019 at 20:50 review Close votes
Jul 6, 2019 at 3:05
Jun 19, 2019 at 20:30 review First posts
Jun 20, 2019 at 2:14
Jun 19, 2019 at 20:28 history asked The Pax Bisonica CC BY-SA 4.0