mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
length() returning 0 for Dynamic object with keys #202
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @fhalde on GitHub (Sep 10, 2024).
I have the following json file
and the following pkl file
the output of the trace is
What could be going on?
The documentation of length() in Dynamic states
@bioball commented on GitHub (Sep 10, 2024):
Pkl has three types of object members: properties, elements, and entries (see explanation here).
Dynamic.length, as you pointed out, will count the number of elements, and your object there has a property and no elements.Try parsing into
Mappinginstead ofDynamic. This will parse JSON objects asMapping, whereMapping#lengthcounts the number of entries (note, this isn't the same thing as properties). Parsing intoDynamicalso has some other issues; for example, it hides any JSON properties called "default".@fhalde commented on GitHub (Sep 10, 2024):
this worked ! thank you :)