Api returns int for text value?



I have defined a field called Postcode and set the type text. When I enter postcode 85221 and save the collection even though this field defined as text api converts it to int inside the json. Is this expacted behaviour? How can I force api to return this value as string.



I looked into the database and it happens on save. So it’s not an output problem.

Just tested with commenting out these two lines:

Now int values are stored as strings and the api output is string, too. But I don’t understand why the checks are there. //JSON_NUMERIC_CHECK - without destroying values with leading zeros sounds important.


Thanks for pointing out the correct places. Yes it sounds important but also I believe it should not convert text field values to int values? Maybe the field type check would prevent this misbehavior?


No, it really shoudn’t. Some tests in a simple text field:

42e0    --> 42
42e4    --> 420000
 42     --> 42
  42    --> 42
.42     --> 0.42
4.2     --> 4.2
-42     --> -42
+42     --> 42
4 2     --> "4 2"
42-     --> "42-"
+-42    --> "+-42"

There is no number field/component to check against, but it looks like there was one in the past - https://github.com/agentejo/cockpit/blob/next/modules/Collections/bootstrap.php#L311

@artur Is there a reason for this type conversion?


I created an issue on Github and pointed this discussion. https://github.com/agentejo/cockpit/issues/907