-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parsing JSON in Skylark #1813
Comments
I don't think so. I would consider farming that task out to a helper python script. Implementing a JSON parser would be pretty difficult without recursion. |
Yeah but then I need to use certain values from that JSON to pass onto other build steps, as it gets very messy. So farming out to helpers would be non ideal as a bunch of work would get duplicated in each helper function. Would there be a chance this could get added to the built in functions for Skylark? I feel this could be a pretty common task. |
@rockwotj : What's in the JSON data that you need to process in Skylark? How would the Skylark code use this data? In principle the only way to process this data is creating Skylark structures from it using a tool pre-build that converts the data, as @pcj suggested, then I don't think we have JSON parsing on the roadmap, but I'm looping in @laurentlb to confirm. |
Similar to |
cc @aj-michael, who's interested in Cocoapod support. |
Haha, I had been asking around on behalf of @mcdonamp who I'm sure is already aware of this effort. Hi Tyler! |
Haha great! Hey Michael, long time no talk. @mcdonamp has talked about it enough I figured it'd be a good side project. |
In case anyone else is curious, I think this can be accomplished manually in today's world by doing something like this: https://gist.github.com/mcdonamp/1f0799e38d1e96a993319da4645fa0b4 I think @rockwotj has made it a little cleaner (autogening the As Tyler said, we need the ability to parse the |
@rockwotj fyi you may already be aware of this tool in rules_go named "gazelle" which autogenerates BUILD files for golang. You may or may not be interested in using go but then you can use buildifier as well. |
@pcj I was not. Thanks for the link! I'll probably look into that. |
Seems like this was resolved, closing :) |
For future readers: there doesn't yet exist a JSON parser in Starlark (or even Skylib), the discussion is continuing here: #3732 |
This change predeclares 'json', the new Starlark module for JSON encoding/decoding/indenting, in all Bazel Starlark environments (alongside depset, select, etc). The new function works for any legal value, not just struct, and avoids polluting the struct field namespace. struct.to_json is deprecated, along with struct.to_proto, and will be disabled by the new flag --incompatible_struct_has_no_methods. (The replacement for to_proto will be added shortly.) Updates bazelbuild/starlark#83 Updates #3732 Updates #1813 RELNOTES: The Starlark json module is now available. Use json.encode(x) to encode a Starlark value as JSON. struct.to_json(x) is deprecated and will be disabled by the --incompatible_struct_has_no_methods flag. PiperOrigin-RevId: 338259618
More explicitly: this now exists: https://docs.bazel.build/versions/master/skylark/lib/json.html |
I'm trying to write a Skylark Extension and need to work with JSON data. Is there a way to load a JSON string into a struct or dict without implementing a json parser in my .bzl file?
The text was updated successfully, but these errors were encountered: