# Is there a Julia package allowing to access json objects like jqlang?

**URL:** <https://discourse.julialang.org/t/is-there-a-julia-package-allowing-to-access-json-objects-like-jqlang/106839>\
**Category:** General Usage\
**Tags:** json, jqlang\
**Created:** [November 28, 2023, 11:34am UTC](https://discourse.julialang.org/t/is-there-a-julia-package-allowing-to-access-json-objects-like-jqlang/106839 "2023-11-28T11:34:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![HugoTrentesaux](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hugotrentesaux/32/12583_2.png) [@HugoTrentesaux](https://discourse.julialang.org/u/HugoTrentesaux)\
**Post date:** [November 28, 2023, 11:34am UTC](https://discourse.julialang.org/t/is-there-a-julia-package-allowing-to-access-json-objects-like-jqlang/106839/1 "2023-11-28T11:34:09Z")

</div>

In REPL it’s convenient to use [jqlang](https://jqlang.github.io/jq/) syntax like

```sh
curl 'https://<graphql-api>' -X POST \
  -H 'content-type: application/json' \
  --data """<graphql-query>""" | \
jq '.data.blocks[0].number

```

is there a way to do something similar in Julia?

It’s already very convenient to do something like:

```julia
using JSON3, Pipe
@pipe read("data.json") |> JSON3.read |>
  getindex(_, :data) |> getindex(_, :blocks) |> getindex(_, 1)

```

but I am looking for a more compact way to explore the json object, it’s a bit cumbersome to call `getindex` multiple times.

---

<div class="post-metadata">

**Author:** ![lmshk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmshk/32/29632_2.png) [@lmshk](https://discourse.julialang.org/u/lmshk)\
**Post date:** [November 28, 2023, 1:37pm UTC](https://discourse.julialang.org/t/is-there-a-julia-package-allowing-to-access-json-objects-like-jqlang/106839/2 "2023-11-28T13:37:54Z")

</div>

Not sure if it solves your problem, but you can call `getindex` implicitly via indexing, e.g. (following your example):

```julia
@pipe read("data.json") |> JSON3.read |> _[:data] |> _[:blocks] |> _[1]

```

or even:

```julia
@pipe "data.json" |> read |> JSON3.read |> _[:data][:blocks][1]

```

Also check out [this presentation at JuliaCon 2023](https://www.youtube.com/watch?v=rKLVkeJkQUs).

---

<div class="post-metadata">

**Author:** ![HanD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hand/32/213908_2.png) [@HanD](https://discourse.julialang.org/u/HanD)\
**Post date:** [November 28, 2023, 1:51pm UTC](https://discourse.julialang.org/t/is-there-a-julia-package-allowing-to-access-json-objects-like-jqlang/106839/3 "2023-11-28T13:51:32Z")

</div>

You can try using [PropertyDicts](https://github.com/JuliaCollections/PropertyDicts.jl) to simplify field access via properties:

```julia
julia> using JSON, PropertyDicts
julia> content = JSON.parsefile("/path/to/my.json"; dicttype = PropertyDict);
julia> content.data.blocks[1].number

```

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [November 28, 2023, 1:56pm UTC](https://discourse.julialang.org/t/is-there-a-julia-package-allowing-to-access-json-objects-like-jqlang/106839/4 "2023-11-28T13:56:15Z")

</div>

If you like `jq` you can use it directly from `jq_jll.jl`:

```julia
julia> using JSON3, jq_jll

julia> jq(data, expr) = sprint(io -> run(pipeline(IOBuffer(data), `$(jq_jll.jq()) -c $expr`, io)))
jq (generic function with 1 method)

julia> jq("""{"x": [{"y": 1},{"y": 2}]}""", "[.x[].y]") |> JSON3.read
2-element JSON3.Array{Int64, Base.CodeUnits{UInt8, String}, Vector{UInt64}}:
 1
 2

```

---

<div class="post-metadata">

**Author:** ![HugoTrentesaux](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hugotrentesaux/32/12583_2.png) [@HugoTrentesaux](https://discourse.julialang.org/u/HugoTrentesaux)\
**Post date:** [November 30, 2023, 3:10pm UTC](https://discourse.julialang.org/t/is-there-a-julia-package-allowing-to-access-json-objects-like-jqlang/106839/5 "2023-11-30T15:10:23Z")

</div>

> [@lmshk](#):
>
> Also check out [this presentation at JuliaCon 2023](https://www.youtube.com/watch?v=rKLVkeJkQUs).

I’ve been using JSON3 a lot without knowing the motivations behind it, thanks for the share 😉

---

<div class="post-metadata">

**Author:** ![slumpy](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@slumpy](https://discourse.julialang.org/u/slumpy)\
**Post date:** [May 2, 2025, 3:46pm UTC](https://discourse.julialang.org/t/is-there-a-julia-package-allowing-to-access-json-objects-like-jqlang/106839/6 "2025-05-02T15:46:12Z")

</div>

Im curious, what is the benefit of using the jll compared to shelling out to regular jq?

You are running it in a subprocess anyway no? Is it simply the ability to install independently from the system binaries?

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [May 2, 2025, 8:47pm UTC](https://discourse.julialang.org/t/is-there-a-julia-package-allowing-to-access-json-objects-like-jqlang/106839/7 "2025-05-02T20:47:39Z")

</div>

It means you don’t need to rely on jq being installed already. And you can control which version you use, just like any other package.
