2

I get an array from the API as follows:

[ { "URL": "", "avatar": "", "characterID": 853, "creationDate": "2022-01-22T17:12:42", "description": "description", "foreignSuggestionID": 0, "id": 5, "seriesID": 0, "type": "IMAGE", "userID": 168314031248113660 } ]

However I expect

[ { "URL": "", "avatar": "", "characterID": 853, "creationDate": "2022-01-22T17:12:42", "description": "description", "foreignSuggestionID": 0, "id": 5, "seriesID": 0, "type": "IMAGE", "userID": 168314031248113664} ]

The userID gets transformed in the request by Javascript, since when I use transformResponse: data => data I get the correct ID. This gets me to the conclusion that it cannot contain the large number in Javascript. My question here would be, is there a way to make sure that a specific value within the json array is seen as a bigint or can I convert the column into a string on receiving the response?

I use axios and my code is as follows:

this.$axios.get(url, {
  withCredentials: 'true'
})
.then(response => {
  this.data = response.data
})
King Reload
  • 2,780
  • 1
  • 17
  • 42
  • Maybe it's related to [BigInt not transforming to JSON correctly](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#use_within_json) – Raz Luvaton Jan 22 '22 at 19:01
  • 1
    Does https://stackoverflow.com/questions/65152373/typescript-serialize-bigint-in-json help? – Ray Toal Jan 22 '22 at 19:02
  • @RazLuvaton sadly this creates a bigint from the entire json response, which I'm not looking for, I'm trying to convert that specific value within the json array to a bigint / string. – King Reload Jan 22 '22 at 19:06
  • @RayToal This is the same example as Raz sent (: so same concept applies – King Reload Jan 22 '22 at 19:07
  • 1
    Maybe [this](https://stackoverflow.com/q/43787712/5923666) will help you? :) – Raz Luvaton Jan 22 '22 at 19:23
  • @RazLuvaton this works when there's a single value in the json string, however when there's multiple values, it does not seem to work, which makes me think it might be similar to the previous answer. I need to be able to convert a specific value within the json array to a bigint or string, however I still need the data to maintain its state of being json. – King Reload Jan 22 '22 at 19:29
  • If you have access to the server, why not just pass a string instead? – code Jan 22 '22 at 19:31
  • @code that is possible, but I want to be able to consider both options, instead of going for the obvious when there's no answer on stackoverflow available to this question. Plus, if similar issues arise with an auto incremented database column, I'd want to be able to use the javascript solution rather than restarting the server and converting integers to strings. – King Reload Jan 22 '22 at 19:34

0 Answers0