---
title: "gojq: value aliasing in the |= operator in Go | VulCode"
description: "A fix in gojq in Go: the |= operator no longer silently changes several copies of one value when update paths overlap, so the output matches jq."
url: "https://vulcode.com/en/opensource/contributions/gojq"
lang: "en"
---

[All contributions](https://vulcode.com/en/opensource/contributions)

itchyny/gojq

# gojq

A pure Go implementation of jq, for processing JSON on the command line and as a library inside Go programs.

[See the repository](https://github.com/itchyny/gojq) [All contributions](https://vulcode.com/en/opensource/contributions)

- **Language**: Go
- **GitHub stars**: 3,821
- **Merged changes**: 1

## What we changed

The |= update operator no longer changes one value in several places at once: when an updated value is handed to a query, later updates work on a copy of it, and the output matches jq.

### What this work shows

- A query compiler and virtual machine in Go

- Aliasing (shared values) and in-place mutation

- jq compatibility

What was broken

### One update changed several places

When an update path was a prefix of an earlier one, getpath handed the update function a value from the allocator, which it could store in several places. The query (.a.b, .a, .a.p.z) |= {p: ., q: .} added "z" to both .a.p and .a.q, while jq adds it only to .a.p.

How we fixed it

### A value that escapes gets copied

A new funcGetpathWithAllocator releases the allocator when it hands out a value the allocator created, so later updates copy it. Two tests in cli/test.yaml cover overlapping paths, nested ones included.

[#306](https://github.com/itchyny/gojq/pull/306)

## Merged change 1

- [#306 fix: release the allocator when an updated value escapes to a query Merged 14 September 2026](https://github.com/itchyny/gojq/pull/306)

## What it taught us

An optimisation that modifies a value in place is safe only while nobody else holds a reference to it. The reference jq implementation set the expected output, and the tests cover overlapping paths, nested ones included.

[More about this technology: Golang](https://vulcode.com/en/technologies/go)

## Other projects we write code for

- [**urfave/cli** Go · 24,329 stars A declarative Go package for building command line tools.](https://vulcode.com/en/opensource/contributions/urfave-cli)

- [**chezmoi** Go · 22,342 stars A dotfiles manager that keeps the same settings on many different machines, securely.](https://vulcode.com/en/opensource/contributions/chezmoi)

- [**goquery** Go · 14,995 stars A Go library for traversing and changing HTML documents in the style of jQuery, built on the golang.org/x/net/html parser.](https://vulcode.com/en/opensource/contributions/goquery)

- [**Ebitengine** Go · 13,647 stars A 2D game engine in Go, used in games released for computers, phones, browsers and consoles.](https://vulcode.com/en/opensource/contributions/ebiten)

- [**Fission** Go · 8,950 stars A serverless functions framework for Kubernetes that runs code as functions and scales them down to zero when they are idle.](https://vulcode.com/en/opensource/contributions/fission)

- [**Concourse** Go · 7,944 stars A container-based automation system written in Go and used mostly for CI/CD. Pipelines and tasks are described in YAML files.](https://vulcode.com/en/opensource/contributions/concourse)

## Describe your project.

A free quote comes back within an hour during working hours.

### Rather skip the form?

Ask in the chat or write to us directly.

Open the chat

- **Email**: [hello@vulcode.com](mailto:hello@vulcode.com)
- **Phone**: [+48 576 043 920](tel:+48576043920)
- **Discord**: [discord.gg/vulcode](https://discord.gg/vulcode)
