Skip to content

Commit

Permalink
starlark/lib/json: a JSON module for Starlark
Browse files Browse the repository at this point in the history
This CL ports the go.starlark.net/starlarkjson module from Go to Java.
The json module provides four functions:

  json.decode
  json.encode
  json.indent        (not yet implemented)
  json.encode_indent (not yet implemented)

It is tested through eval.ScriptTest, which adds the json module to
its environment, along with 'struct', a simple struct-like type.

Some tests are commented out, awaiting StarlarkFloat, or richer string support.

This is a first step towards removing Bazel's struct.to_json.

Updates bazelbuild/starlark#83

PiperOrigin-RevId: 337944489
  • Loading branch information
adonovan authored and copybara-github committed Oct 19, 2020
1 parent 6cb560f commit 6e47a40
Show file tree
Hide file tree
Showing 6 changed files with 931 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ filegroup(
"//src/main/java/com/google/devtools/common/options:srcs",
"//src/main/java/net/starlark/java/cmd:srcs",
"//src/main/java/net/starlark/java/spelling:srcs",
"//src/main/java/net/starlark/java/lib/json:srcs",
"//src/main/native:srcs",
"//src/main/protobuf:srcs",
"//src/main/tools:srcs",
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/net/starlark/java/lib/json/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
load("@rules_java//java:defs.bzl", "java_library")

licenses(["notice"])

filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//src:__subpackages__"],
)

# Starlark json module
java_library(
name = "json",
srcs = ["Json.java"],
visibility = ["//src/main/java/net/starlark/java:clients"],
deps = [
"//src/main/java/net/starlark/java/annot",
"//src/main/java/net/starlark/java/eval",
"//src/main/java/net/starlark/java/syntax",
],
)
Loading

0 comments on commit 6e47a40

Please sign in to comment.