0

i have this following string to parse as JSON and send as post request. not sure what is the best way to do this:

start=0&page_length=50&exclude_vehicle_category=%5B%5D&toll_non_toll=false&mode=%22detail_state_mileage_report%22&scope_kind=%22enterprise_group%22&scope_value=4317&scope_values=%7B%22enterprise_group%22%3A%204317%7D&start_date=%7B%22snap_unit%22%3A%20%22day%22%2C%20%22snap_direction%22%3A%20%22beginning%22%7D&end_date=%7B%7D&time_zone=%22EST%22&columns=%5B%22GROUPNAME%22%2C%20%22VEHICLEID%22%2C%20%22VEHICLENAME%22%2C%20%22VEHICLETAG%22%2C%20%22VEHICLE_VIN%22%2C%20%22TOTAL_DISTANCE_DRIVEN%22%2C%20%22TOTAL_DISTANCE_DRIVEN_OH%22%5D&coloring=%5B%5D&sort=%5B%5B%22GROUPNAME%22%2C%20false%5D%2C%20%5B%22VEHICLEID%22%2C%20false%5D%5D

2 Answers 2

2

Say s contains your string:

hash = {}   
s.split("&").each do |key_value|
  key, value = key_value.split("=")
  hash[key.to_sym] = value
end
hash.to_json
Sign up to request clarification or add additional context in comments.

Comments

0
Rack::Utils.parse_query(s)
=> {"start"=>"0",
    "page_length"=>"50",
    "exclude_vehicle_category"=>"[]",
    "toll_non_toll"=>"false",
    "mode"=>"\"detail_state_mileage_report\"",
    "scope_kind"=>"\"enterprise_group\"",
    "scope_value"=>"4317",
    "scope_values"=>"{\"enterprise_group\": 4317}",
    "start_date"=>"{\"snap_unit\": \"day\", \"snap_direction\": \"beginning\"}",
    "end_date"=>"{}",
    "time_zone"=>"\"EST\"",
    "columns"=>"[\"GROUPNAME\", \"VEHICLEID\", \"VEHICLENAME\", \"VEHICLETAG\", \"VEHICLE_VIN\", \"TOTAL_DISTANCE_DRIVEN\", \"TOTAL_DISTANCE_DRIVEN_OH\"]",
    "coloring"=>"[]",
    "sort"=>"[[\"GROUPNAME\", false],[\"VEHICLEID\", false]]"
   } 

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.