jsonnet icon indicating copy to clipboard operation
jsonnet copied to clipboard

Add ability to refer to subfields of objects via dot notation in string formatting

Open fedya-at-db opened this issue 3 years ago • 2 comments

You can now do something like this: "%(a.b)s" % {a:{b:"hello world"}} which yields "hello world"

This is similar to python3's format strings behavior, though much simpler in capability. Every subfield must be an object except the last one.

Tested: added new happy path format test, and an error test

fedya-at-db avatar Jul 30 '22 07:07 fedya-at-db

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

google-cla[bot] avatar Jul 30 '22 07:07 google-cla[bot]

@sparkprime Hi, wanted to check what you thought of this PR.

fedya-at-db avatar Sep 08 '22 02:09 fedya-at-db

I only just noticed this. It seems like it could be useful for a fair few cases but it's a bit too big for the release I'm just doing.

sparkprime avatar Apr 13 '23 12:04 sparkprime

At this point I've used a workaround like "%(b)s" % {b: a.b} but I'm still happy to submit this if you think it's a usability improvement.

fedya-at-db avatar Apr 13 '23 16:04 fedya-at-db