Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Commit 0521a2f

Browse files
committed
Document propertyNames
1 parent 9bd14f6 commit 0521a2f

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

source/reference/object.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,43 @@ they don't provide their address or telephone number:
234234
"address": "Henley Street, Stratford-upon-Avon, Warwickshire, England",
235235
}
236236

237+
.. index::
238+
single: object; property names
239+
single: propertyNames
240+
241+
Property names
242+
''''''''''''''
243+
244+
|draft6|
245+
246+
The names of properties can be validated against a schema, irrespective of their
247+
values. This can be useful if you don't want to enforce a specific properties,
248+
but you want to make sure that the names of those properties follow a specific
249+
convention. You might, for example, want to enforce that all names are valid
250+
ASCII tokens so they can be used as attributes in a particular programming
251+
language.
252+
253+
.. schema_example::
254+
255+
{
256+
"type": "object",
257+
"propertyNames": {
258+
"pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
259+
}
260+
}
261+
--
262+
{
263+
"_a_proper_token_001": "value"
264+
}
265+
--X
266+
{
267+
"001 invalid": "value"
268+
}
269+
270+
Since object keys must always be strings anyway, so it is implied that the
271+
schema given to ``propertyNames`` is always at least::
272+
273+
{ "type": "string" }
237274

238275
.. index::
239276
single: object; size

0 commit comments

Comments
 (0)