1

How can I have this structure in a query string?

"properties": {
        "list": [
            {
                "label": "bye",
                "value": "world"
            },
            {
                "label": "hello",
                "value": "mars"
            }
        ]
    }

I've tried it with properties[][list][label]=bye&properties[][list][value]=world&properties[0][label]=hello&properties[0][value]=mars and also with properties[][list][label]=bye&properties[][list][value]=world&properties[][list][label]=hello&properties[][list][value]=mars, none of them worked. I built them in php with http_build_query.

I need to have this structure in a query string because I have to send the data along with some other stuff with POST to a PHP site.

2
  • How about sending it as a JSON string? the newlines are just for human reading, you can just do it all in a single line and then use json_decode in PHP. Commented Mar 8, 2018 at 15:10
  • Well the problem is that I can't send it via PHP, instead I have to use something similar to cURL. Commented Mar 8, 2018 at 15:12

1 Answer 1

3

I see two errors in your query string:

  • properties is an object, so there's no need to use [] to add elements.
  • list is an array, so you must use numeric indexes in the query string.

The correct query string is:

?properties[list][0][label]=bye
&properties[list][0][value]=world
&properties[list][1][label]=hello
&properties[list][1][value]=mars

(multi-lined for readability)

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

4 Comments

Yes, thank you that's it! And so fast. Thank you so much.
@User2093587239023: you're welcome! Be sure to mark the answer as accepted if that solved your problem.
Yes I will, but StackOverflow said I have to wait 8 minutes ;)
is there any standard for complex query string like this?

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.