I am trying to convert the parameters from my URL (Example 1) to a JSON Object that looks like Example 2. Unfortunately when I use JSON.stringify() it converts it to Example 3. Can anyone please point me in the right direction for splitting this? I am not sure how to get the keys out.
Example 1 - Input
food=apple,banana,peach&store=walmart&customer=John
Example 2 - Desired Output
{"food": ["apple", "banana", "peach"], "store":"walmart", "customer":"John"}
Example 3 - Current Ouput
{"food=apple,banana,peach", "store=walmart", "customer=John"}
Edits:
Forgot "" in food list
What I tried
data = "food=apple,banana,peach&store=walmart&customer=John";
data = JSON.stringify(data);