Is there any Pattern related to the typing or not of values in the return of JSON in API’s?

Asked

Viewed 57 times

0

I wonder if there is any problem involved in passing the values of the keys in JSON all as string or if there is any justification to always keep the original types of data?

My question is based on the fact that a while ago I had some problems with passing values in Float, specifically in PHP with json_encode, and in one OS topic had found an explanation of the problem, which was even the solution (https://stackoverflow.com/questions/42981409/php7-1-json-encode-float-issue). Meanwhile I always passed all float values of a JSON as String in developing API’s to avoid this kind of problem.

Is there any recommendation/justification regarding the typing or not of the values in JSON when developing an API? Or is it really something "irrelevant" and is at the mercy of the developer set the standard that is useful to you?

I ask this because I’ve had to consume API’s with several different types of patterns, either passing all values as String, or maintaining the original typing of values, some even performing the mixing of the two situations (some keys with integer/decimal values as string others keeping typing).

1 answer

1


Patterns concern how to work with the objects and architecture of the system and not a specific object type. It will depend on the problem you are dealing with, how you did your system architecture and what documentation of the toolset you are using suggests.

Is there any recommendation/justification regarding the typing or not of the values in JSON when developing an API? Or is it really something "irrelevant" and is at the mercy of the developer set the standard that is useful to you?

It will depend on your architecture, if any framework is used, usually it suggests, and this will follow some architectural model, preferably.

  • 1

    I had imagined that it was really this, considering that there were no other answers, I suppose that in fact it did not have a "recommended standard" for this. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.