I am trying to set a value in a Data Jar entry using a key structure that looks like the following:
tr.2021.01.01010014
That is a direct copy from the output of the Quick Look in snippet shown on the left side of the following image
The first 2 keys (tr and 2021) are recognized, but “Index 1” is being substituted for what should be “01”.
The Data Jar entry that is created is on the right. The correct values are being stored. Any ideas why “Index 1” being substituted for part of the key structure?
It looks like a bug to me as to how the content is being interpreted.
Changing the third element have me very specific, and varying, results:
- 01 => Creates Index 1
- 1 => Creates Index 1
- 001 => Creates Index 1
- \01 => Creates 01
- 02 => Creates 02
One for @simonbs to investigate further I think.
As far as I can tell the element at tr.2021.01
didn’t exist before running this shortcut. That is, Data Jar created the item at tr.2021.01
. Since 01
is a valid way to refer to the first element in an array, Data Jar will assume that you’d like it to create an array.
You should be able to change this behaviour by explicitly marking 01
as a key in a dictionary by wrapping it in quotes like this: tr.2021."01"
.
Can you try that and let me know if the issue persists?
Thanks Simon.
Does that follow if 02 is a way to refer to the second element in an array but does not create an array? Is it just this edge case for the first element where it differs in behaviour? If so, is that the desired behaviour for this action? Should we effectively always quote elements to be explicit?
That shouldn’t create an array because index 02 (or rather index 2) is out of bounds for an array that doesn’t exist. That same could be said for index 1, however, long ago I decided on creating an array instead.
Yes.
It’s the intended behavior at least. From my testing back when I started developing Data Jar, I found it handy that it would create an array when specifying index 1. For example, when looping over a range and adding a value for each element. Instead of creating the array upfront, Data Jar will automatically create the array when adding the first element.
That’s the safe thing to do for numeric elements in a key path.
Thanks for the follow-up and very helpful explanation. Using “ “ around the numeric index (represents the week number) solved the problem. Thanks again — jay