> For the complete documentation index, see [llms.txt](https://jscula.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jscula.gitbook.io/docs/location/queryobject.md).

# queryObject

The `queryObject` function parses a URL's query string into a structured JavaScript object. It supports nested objects, arrays, and automatic type conversion for numbers and booleans.

***

## Examples

### Basic Query Parsing

For a URL: `https://example.com?page_id=12&active=true&category=books&token=8b3a2ca1fa73n31e`

```javascript
window.location.queryObject();
// Output: { page_id: 12, active: true, category: "books",token:"8b3a2ca1fa73n31e" }
```

### Nested Query Keys

For a URL: `https://example.com?user.name=John&user.age=30`

```javascript
window.location.queryObject();
// Output: { user: { name: 'John', age: 30 } }
```

### Array Values

For a URL: `https://example.com?tags[]=js&tags[]=html&tags[]=css`

```javascript
window.location.queryObject();
// Output: { tags: ['js', 'html', 'css'] }
```

### Combination of Nested and Arrays

For a URL: `https://example.com?user.hobbies[]=coding&user.hobbies[]=reading`

```javascript
window.location.queryObject();
// Output: { user: { hobbies: ['coding', 'reading'] } }
```

### Malformed Query Handling

For a URL: `https://example.com?valid=true&malformed%`

```javascript
window.location.queryObject(); 
// Output: { valid: true } 
// Logs: Malformed query string pair detected: "malformed%". It has been skipped.
```

***

## Key Features

1. **Automatic Type Conversion**: Converts numbers (`123` → `123`), booleans (`true` → `true`), and retains strings.
2. **Nested Key Support**: Easily handles dot-separated keys (`user.name`).
3. **Array Support**: Recognizes keys ending with `[]` as arrays.
4. **Graceful Degradation**: Skips malformed query pairs with a warning.

***

## Notes

* Returns `null` if the query string is empty.
* Highly customizable for various URL query formats.
