"Number" field not returning a number in the JSON response 🧐

Hi guys,
My count fields are set to numbers
image
yet the response from the GET call returns text:

[
    {
        "id": 1,
        "order": "1.00000000000000000000",
        "category": "Stay",
        "price": "149",
        "currency": "EUR",
        "country": "Germany",
        "count": "3"
    },

What is the workaround to turn “count” and “order” in to numbers?

You can think of a number field as a decimal field with a set number of decimal places. It is returned as string to preserve the number of decimal places set.

1 Like

Ok thanks, I’ll use a NUMBER() formula then.

1 Like

This decimal field keeps giving me massive troubles as I cannot always us the NUMBER() or INTEGER() formula to reformat the field. I may have to drop the project on Baserow because of that, unless you are able to address the issue.
I see many (really all useful? I doubt so) options here but you could add an option for a real number in the dropdown.
image
Why have you implemented so many decimal options and none for a real number?

@Fred are you specifically asking that we add a floating point number field type to Baserow? Or are you having trouble instead converting this JSON string into a number in your software?

Please refer to this page to understand why we return our number field as a string in the JSON serialization - Why would you use a string in JSON to represent a decimal number - Stack Overflow and also What are floating point errors? [Answered] | Penjee, Learn to Code .

Could you go into more detail on the software you are using the parse the JSON responses from Baserow with? What exactly are the NUMBER and INTEGER formulas you refer to as we could help you parse the returned number correctly and solve your problem.

Nigel, appreciate your intervention on the weekend.
When I make a call, here is the response, with a string (“count”: “3”) instead of an ideal number (“count”: 3):

{
        "id": 1,
        "order": "1.00000000000000000000",
        "category": "Stay",
        "price": "149",
        "currency": "EUR",
        "country": "Germany",
        "count": "3"
    }

I’m using two no code tools: Flutter Flow and AppGyver and two DBs: Firebase and yours, depending on the data I want to fetch.
I use these types of formulas to process the data:

"("+SUM_BY_KEY(data.getCounters[0].stay, "count") + " options)"

GROUP(SORT_BY_KEY(FLATTEN(MAP(SELECT(data.ProvidersDB, item.currency == appVars.userCurrency), item.services)),"price"), item.price, {price: key +" ("+ COUNT(items)+")"})

For example, Firebase returns the desired array of objects with number types in the value, like:
[{"price":"149eur", "count": 1},{"price":"129eur", "count": 3},{...}]
Whereas Baserow returns:
[{"price":"149eur", "count": "1"},{"price":"129eur", "count": "3"},{...}]]

I’m simplifying here for the sake of quick understanding. I’m not asking you to figure out the right mapping function, it’s not going to work and I don’t want an overly complexe formula when fetching data from Baserow, when a similar fetch needs a short formula for Firebase.

Not sure what field type per se I need, I know the result I want from the API call response, this: “count”: 3 instead of that: “count”: “3”

Thanks

Right now in Baserow there is no number field type that will respond with raw numbers instead of string wrapped numbers in the JSON api for the reasons outlined above.

I will discuss with the team next week if there is an option to perhaps add a flag to the API allowing an endpoint to return raw numbers instead of string numbers. But otherwise you will have to change your AppGyver formula to parse the count from a string to a number.

If the problem you are hitting in AppGyver is that SUM_BY_KEY doesn’t work for strings, could you instead try using a map function like so:
SUM(MAP(data.getCounters[0].stay, Number(item.count)))
Such a formula should now handle both Baserow’s response and Firebases.

Thanks but the formula with the issue is more complexe: I cannot assign a list to NUMBER() which is text or number type.
FYI GROUP(MAP(SELECT(SELECT(data.readCounts, item.currency == appVars.userCurrency), item.category == "Stay"), item.price), item, {price:key + " "+ NUMBER(items)})

Best is to be patient until you can add that “raw number” capability so I can process the value as is in my formula.
All that’s needed is an additional raw number option here
image

Hi Fred i’ve made the following issue to track this proposal. The idea being you could call the rows api endpoint with the ?return_raw_numbers=true flag to get numbers in your JSON instead. Proposal: Add a new return_raw_numbers API flag (#1069) · Issues · Bram Wiepjes / baserow · GitLab

1 Like

Very much appreciated Nigel.
Will this translate in the UI to the ability to simply select a ‘raw number’ option in the field type dropdown list?

No this would be API only. I don’t think it would make sense to show in the GUI for users as what is a “Raw number” from the users point of view? The users just want to control the number of decimal places they see in the GUI. Instead this flag would be API only as it is a technical API only concern if that makes sense.

So when you send your GET API call you would append ?return_raw_numbers=true to the API url you use for Baserow. Just like with the similar user_field_names flag.

Ok so I would make such get request for listing rows:

https://api.baserow.io/api/database/rows/table/77168/?user_field_names=true&return_raw_numbers=true

Yup it would be exactly like that, would it work for you?

1 Like

I believe it would. I’ll have to test it out with FlutterFlow and AppGyver.
I hope other users will benefit from this fix too.