Skip to content

What is jj's long term goal? #27

@MajorDallas

Description

@MajorDallas

tl;dr: I guess if I'm asking for anything with all the following, it's clarification: is feature-parity with jq an eventual goal for jj, or is it meant to only ever serve for easier access of JSON values in Go app code?

Although tidwall/gjson#161 provided one necessary capability, this kind of task remains impossible with GJSON path syntax and jj. I have a nested structure, but I'm only interested in how many times a certain key has the same value across all objects:

# diagnostics.json
{
  "nodes": {
    "000-000-0000": {
      "node_type": "server"
    },
    "000-111-0001": {
      "node_type": "asav"
    },
    "222-000-0202": {
      "node_type": "server"
    },
  } 
}

In other words, how many times is node_type "server", "asav", or any other value which I can't know ahead of time?

With jq, this is fairly straightforward:

jq '.nodes 
  | [.[].node_type]  # Makes an array of all sub-objects' node_type values
  | group_by(.)      # Sorts the array and groups alike elements into nested arrays
  | map(             # Makes an object for each nested array like {"key: "server", "value": 2}
    { "key": (.[0]), "value": . | length }
  ) | from_entries  # Turn the arrayed objects into a single object
' diagnostics.json

# {
#    "server": 2,
#    "asav": 1
# }

With jj, I can get as far as making a list of the node_types with

nodes.@values.#.node_type

# ["server", "asav", "server"]

but there is no way to group or even sort this array for further transformation using just jj.

I understand that GJSON is a Go library and those kinds of operations are, not unreasonably, expected to be implemented in app code. However, the README presents jj as an alternative to jq, which describes itself as "sed for JSON." That's a few steps beyond what is currently possible with jj and GJSON's path syntax, so jj is only a viable alternative for a subset of problems which jq aims to address despite its clear speed advantage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions