Skip to content

Commit

Permalink
[Docs] add docs for encodeDotKeys and decodeDotKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
aks- committed Jan 28, 2024
1 parent 02c45e8 commit 0cb6433
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ var withDots = qs.parse('a.b=c', { allowDots: true });
assert.deepEqual(withDots, { a: { b: 'c' } });
```

Option `decodeDotKeys` can be used to decode dot notations in keys
Note: it only works with `allowDots` so you have to provide both options to be `true`:

```javascript
var withDots = qs.parse('name%252Eobj.first=John&name%252Eobj.last=Doe', { allowDots: true, decodeDotKeys: true });
assert.deepEqual(withDots, { 'name.obj': { first: 'John', last: 'Doe' }});
```

Option `allowEmptyArrays` can be used to allowing empty array values in object
```javascript
var withEmptyArrays = qs.parse('foo[]&bar=baz', { allowEmptyArrays: true });
Expand Down Expand Up @@ -426,6 +434,13 @@ qs.stringify({ a: { b: { c: 'd', e: 'f' } } }, { allowDots: true });
// 'a.b.c=d&a.b.e=f'
```

You may encode the dot notation in the keys of object with option `encodeDotKeys` by setting it to `true`
Note: it only works with `allowDots` being set to `true`:
```javascript
qs.stringify({ "name.obj": { "first": "John", "last": "Doe" } }, { allowDots: true, encodeDotKeys: true })
// 'name%252Eobj.first=John&name%252Eobj.last=Doe'
```

You may allow empty array values by setting the `allowEmptyArrays` option to `true`:
```javascript
qs.stringify({ foo: [], bar: 'baz' }, { allowEmptyArrays: true });
Expand Down

0 comments on commit 0cb6433

Please sign in to comment.