2

I am using python to generate a query string which will then be parsed by javascript.

Consider a fairly "complex" piece of data:

import urllib

params = {
         'record': 'customer',
         'filters': [
                 ('id', '>', 5),
                 ('name', 'startswith', 'Jean Luc')
         ]
}

urllib.urlencode(params)
'record=customer&filters=%5B%28%27id%27%2C+%27%3E%27%2C+5%29%2C+%28%27name%27%2C+%27startswith%27%2C+%27Jean+Luc%27%29%5D'

urllib.unquote(urllib.urlencode(params))
"record=customer&filters=[('id',+'>',+5),+('name',+'startswith',+'Jean+Luc')]"

In python, I can use urlparse.parse_qs() to take that url-encoded query string and reconstruct a Python structure.

Is there an equivalent for Javascript? Has someone written a library which knows how to parse such querystrings?

Incidentally, this Javascript is not running in a browser - it is an internal scripting functionality in a package called "Netsuite" - so using external javascript libraries is somewhat difficult (though ultimately doable if that is what is required.)

poundifdef
  • 16,490
  • 19
  • 82
  • 126
  • Sounds like you want to use JSON instead; Python -> JSON -> JavaScript is easy and well supported. – Martijn Pieters Dec 26 '12 at 19:00
  • Watch the close votes: It is a semi-duplicate, but not an exact duplicate. The duplicate stops at the key-value extraction and decoding. This question calls for "complex" data as well. –  Dec 26 '12 at 19:15
  • this question isn't a duplicate, much less an 'exact' one... – poundifdef Dec 26 '12 at 22:42

2 Answers2

1

jQuery.deparam might be what you're looking for. Should be easy enough to look at his source and figure out how to do it if you can't use jQuery in Netsuite.

Chris Doggett
  • 17,776
  • 4
  • 55
  • 84
0

Its best to use either XML or JSON form of data to the Netsuite end.

and Netsuite scripts are pure javascript here, JQuery is not supported but JSON and XML data can be parsed back to the objects using JSON.Parse and you can continue using the data there.

Cheers!!!

Amit
  • 2,305
  • 11
  • 21