1

I'm trying to pass nested arrays parameters from React App to Express Server via axios. Client side and URL format looks good but on server side these nested arrays' items are converted into string

POST nested array output:

filter = [[1], [2], [3]]

Express server received req.query output

filter = ['[1]', '[2]', '[3]']

so it fails because it's expecting nested arrays.

Request URL

http://localhost:3006/api/filtertable?page=0&pageSize=5&isFilter=true&filter[]=[1]&filter[]=[2]&filter[]=[3]

1 Answer 1

1

The issue is that GET requests with parameters can only accept primitive data and arrays of primitive data.

Now you could parse these values on your server like so:

app.get('/api/filterable', (req, res, next) => {
 var filter = req.query.filter.map(f => JSON.parse(f));
 // Do whatever else you need with it
});

Or you could also use a different HTTP method that allows sending JSON data, like POST.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.