Parse the query as typed in the box and confirm it is valid JSON
967401
function parseQuery() {
  let query = {};

  try { query = JSON.parse(queryBox.value); }
  catch(error) {
    queryError.textContent = 'Query must be valid JSON';
    hide(queryButton);
    hide(queryResults);
    show(queryError);
    return null;
  } 

  hide(queryError);
  show(queryButton);
  return query;
}
721863
def raw(self, query: Any, data: Any = None):
        
        assert isinstance(query, str)

        conn = self.get_connection()
        items = []

        for schema_name in conn['data']:
            input_db = conn['data'][schema_name]
            try:
                # Ensures that the string contains double quotes around keys and values
                query = query.replace("'", "\"")
                criteria = json.loads(query)

                for key, value in criteria.items():
                    input_db = self._evaluate_lookup(key, value, False, input_db)

                items.extend(list(input_db.values()))

            except json.JSONDecodeError:
                # FIXME Log Exception
                raise Exception("Query Malformed")
            except KeyError:
                # We encountered a repository where the key was not found
                pass

        return items
582220
function (json, callback) {
        //validate input
        if (!inputValidation(json)) {
            var inputError = new SearchError('invalid input');
            callback(undefined, inputError);
            return;
        }
        var number = json.number;
        //mongodb api here, then handle the response from mongodb
        database.getSentimentTimeframe(json.startDate, json.endDate, function (json, err) {
            if (err) {
                callback(undefined, err);
            } else {
                var res = calculateTopSum(json, number, ["posSum"]);
                callback(res);
            }
        });
    }
994991
function parseQueryString(query) {
  var parts = query.split('&');
  var params = {};
  for (var i = 0, ii = parts.length; i < ii; ++i) {
    var param = parts[i].split('=');
    var key = param[0].toLowerCase();
    var value = param.length > 1 ? param[1] : null;
    params[decodeURIComponent(key)] = decodeURIComponent(value);
  }
  return params;
}
1253745
def is_json(self, headers):
        """"""
        ret = False
        ct = headers.get("content-type", "").lower()
        if ct:
            ret = ct.lower().rfind("json") >= 0
        return ret
216859
def parse_query(str)
      query = Hash.new
      if str
        str.split(/[&;]/).each{|x|
          next if x.empty?
          key, val = x.split(/=/,2)
          key = unescape_form(key)
          val = unescape_form(val.to_s)
          val = FormData.new(val)
          val.name = key
          if query.has_key?(key)
            query[key].append_data(val)
            next
          end
          query[key] = val
        }
      end
      query
    end
1064818
function checkQuery(expected, actual){
    if(!expected){
        return;
    }

    //Ignore trailing ampersands
    var actualObj = actual ? queryString.parse(actual.replace(/\&$/, '')) : {};
    var expectedObj = queryString.parse(expected);

    if(! _.isEqual(actualObj, expectedObj)){
        return {
            error: "Query parameters do not match",
            expected: expectedObj,
            actual: actualObj
        };
    }
}
1102246
function parseArgs() {
    var args = Array.prototype.slice.call(arguments);

    var ret = {
        query: args[0],
        params: [],
        options: {},
        callback: undefined,
        endCallback: undefined
    };

    args.shift();

    // If specified, params must be an array
    if (args[0] instanceof Array) {
        ret.params = args[0];
        args.shift();
    }

    // If specified, options must be a non-Function object
    if (! (args[0] instanceof Function)) {
        ret.options = args[0];
        args.shift();
    }

    ret.callback = args[0];
    ret.endCallback = args[1];

    if (ret.query === undefined || ret.callback === undefined) {
        throw new Error('query and callback are required');
    }

    return ret;
}
57963
function isJson(str) {
        try {
            var obj = JSON.parse(str);
            return this.isObject(obj);
        } catch (e) {/* ignore */}

        return false;
    }
1169250
def is_valid(draco_query: List[str], debug=False) -> bool:
    
    _, stdout = run_clingo(
        draco_query,
        files=["define.lp", "hard.lp", "hard-integrity.lp"],
        silence_warnings=True,
        debug=debug,
    )

    return json.loads(stdout)["Result"] != "UNSATISFIABLE"
1078726
def _validate_query_parameters(self, query, action_spec):
        
        processed_params = []
        for param_name, param_value in query.items():
            if param_name in action_spec['parameters'].keys():
                processed_params.append(param_name)

                # Check array
                if action_spec['parameters'][param_name]['type'] == 'array':
                    if not isinstance(param_value, list):  # Not an array
                        return False
                    else:
                        for i in param_value:  # Check type of all elements in array
                            if not self.check_type(i, action_spec['parameters'][param_name]['items']['type']):
                                return False

                elif not self.check_type(param_value, action_spec['parameters'][param_name]['type']):
                    return False

        # Check required
        if not all(param in processed_params for param, spec in action_spec['parameters'].items()
                   if spec['in'] == 'query' and 'required' in spec and spec['required']):
            return False
        return True
582259
function isJSONStr(value) {
    if (!lodash.isString(value)) {
        return false;
    }
    try {
        return isJSONObj(JSON.parse(value));
    } catch (e) {
        return false;
    }
}
956205
function parseQuery(str) {
    var i, ps, p, n, k, v, l;
    var pairs = [];

    if (typeof(str) === 'undefined' || str === null || str === '') {
      return pairs;
    }

    if (str.indexOf('?') === 0) {
      str = str.substring(1);
    }

    ps = str.toString().split(re.query_separator);

    for (i = 0, l = ps.length; i < l; i++) {
      p = ps[i];
      n = p.indexOf('=');

      if (n !== 0) {
        k = decode(p.substring(0, n));
        v = decode(p.substring(n + 1));
        pairs.push(n === -1 ? [p, null] : [k, v]);
      }

    }
    return pairs;
  }
363571
function updateQuery() {
  let query = {};

  switch(queryTemplates.value) {
    case '0': // All raddecs
      query = {
          "size": 10,
          "query": { "match_all": {} },
          "_source": [ "transmitterId", "transmitterIdType", "receiverId",
                       "receiverIdType", "rssi", "timestamp",
                       "numberOfDecodings", "numberOfReceivers",
                       "numberOfPackets" ]
      };
      queryBox.value = JSON.stringify(query, null, 2);
      break;
    case '1': // Specific transmitterId
      query = {
          "size": 10,
          "query": { "term": { "transmitterId": "" } },
          "_source": [ "receiverId", "receiverIdType", "rssi", "timestamp",
                       "numberOfDecodings", "numberOfReceivers",
                       "numberOfPackets", "packets" ]
      };
      queryBox.value = JSON.stringify(query, null, 2);
      break;
    case '2': // Prefix transmitterId
      query = {
          "size": 10,
          "query": { "prefix": { "transmitterId": "" } },
          "_source": [ "transmitterId", "transmitterIdType", "receiverId",
                       "receiverIdType", "rssi", "timestamp",
                       "numberOfDecodings", "numberOfReceivers",
                       "numberOfPackets" ]
      };
      queryBox.value = JSON.stringify(query, null, 2);
      break;
    case '3': // Aggregate receiverId
      query = {
          "size": 0,
          "aggs" : {
            "receivers" : {
              "terms" : {
                "field" : "receiverId.keyword",
                "order" : { "_count" : "desc" },
                "size": 12
              }
            }
          }
      };
      queryBox.value = JSON.stringify(query, null, 2);
      break;
    case '4': // Aggregate rec/dec/pac
      query = {
          "size": 0,
          "aggs" : {
            "numberOfReceivers" : {
              "histogram" : {
                "field" : "numberOfReceivers",
                "interval" : 1
              }
            },
            "numberOfDecodings" : {
              "histogram" : {
                "field" : "numberOfDecodings",
                "interval" : 1,
                "min_doc_count" : 1
              }
            },
            "numberOfDistinctPackets" : {
              "histogram" : {
                "field" : "numberOfDistinctPackets",
                "interval" : 1
              }
            }
          }
      };
      queryBox.value = JSON.stringify(query, null, 2);
      break;
    case '5': // Auto-date histogram
      query = {
          "size": 0,
          "aggs" : {
            "periods" : {
              "auto_date_histogram" : {
                "field" : "timestamp",
                "buckets" : 12
              }
            }
          }
      };
      queryBox.value = JSON.stringify(query, null, 2);
      break;
  }
  queryBox.rows = countNumberOfLines(queryBox.value);
  parseQuery();
}
435943
def from_json(cls, json):
    """"""
    obj = cls(key_range.KeyRange.from_json(json["key_range"]),
              model.QuerySpec.from_json(json["query_spec"]))
    cursor = json["cursor"]
    # lint bug. Class method can access protected fields.
    # pylint: disable=protected-access
    if cursor and json["cursor_object"]:
      obj._cursor = datastore_query.Cursor.from_websafe_string(cursor)
    else:
      obj._cursor = cursor
    return obj
84233
def _get_json_obj(self, endpoint, query, is_post=False):
        
        response = self._get_response(endpoint, query, is_post=is_post)
        content = response.text
        try:
            return loads(content)
        except ValueError:
            raise Exception('Could not decode content to JSON:\n%s'
                            % self.__class__.__name__, content)
810740
function parseQuery(str, opts = {}) {
  let _querys = {};
  decodeURIComponent(str || '').replace(/\+/g, ' ')
  // (optional no-capturing & )(key)=(value)
  .replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function ($0, _name, _value) {
    if (_name) {
      let _path, _acc, _tmp, _ref;
      (_path = []).unshift(_name = _name.replace(/\[([^\]]*)]/g, function ($0, _k) {
        _path.push(_k);
        return '';
      }));
      _ref = _querys;
      for (let j = 0; j < _path.length - 1; j++) {
        _acc = _path[j];
        _tmp = _path[j + 1];
        if (!_ref[_acc]) {
          _ref[_acc] = _tmp === '' || /^[0-9]+$/.test(_tmp) ? [] : {};
        }
        _ref = _ref[_acc];
      }
      if (opts.boolval) {
        // first
        if (_value === 'true') {
          _value = true;
        } else if (_value === 'false') {
          _value = false;
        }
      } else if (opts.intval) {
        // skip "true" & "false"
        if (_tmp = parseInt(_value) === _value) {
          _value = _tmp;
        }
      }
      if ((_acc = _path[_path.length - 1]) === '') {
        _ref.push(_value);
      } else {
        _ref[_acc] = _value;
      }
    }
  });
  return _querys;
}