code: def json2pattern(s):
      
      # make valid JSON by wrapping field names in quotes
      s, _ = re.subn(r'([{,])\s*([^,{\s\'"]+)\s*:', ' \\1 "\\2" : ', s)
      # handle shell values that are not valid JSON
      s = shell2json(s)
      # convert to 1 where possible, to get rid of things like new Date(...)
      s, n = re.subn(r'([:,\[])\s*([^{}\[\]"]+?)\s*([,}\]])', '\\1 1 \\3', s)
      # now convert to dictionary, converting unicode to ascii
      try:
          doc = json.loads(s, object_hook=_decode_pattern_dict)
          return json.dumps(doc, sort_keys=True, separators=(', ', ': '))
      except ValueError as ex:
          return None
docs: Convert JSON format to a query pattern.
  
      Includes even mongo shell notation without quoted key names.