Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Marshal Any as the node it wraps instead of {"Node": ...}

Open
#185 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go, json, yaml
Domain
backend

Research direction

Start by reading the definition of Any and its existing UnmarshalJSON method, then inspect how tree.MarshalJSON and MarshalYAML encode nodes. Add coverage for wrapped map values and nil nodes, including Any{} and a typed nil array. Done means JSON and YAML encode the wrapped value directly, nil nodes encode as null, and the release note mentions the output change.

Written by the indexing model from the issue text.

Description

bug

Any exists so that a struct field can hold any JSON value (Node is an interface, so encoding/json cannot decode into it), and (*Any).UnmarshalJSON decodes into the wrapped node. There is no MarshalJSON / MarshalYAML, so encoding marshals the struct itself and the round trip breaks:

type Config struct {
	Name  string   `json:"name"`
	Extra tree.Any `json:"extra"`
}

json.Unmarshal([]byte(`{"name":"a","extra":{"k":1}}`), &c) // c.Extra.Node == Map{"k": 1}
json.Marshal(c) // {"name":"a","extra":{"Node":{"k":1}}}

tree.MarshalJSON(tree.Map{"a": tree.Any{Node: tree.StringValue("x")}}) gives {"a":{"Node":"x"}} and MarshalYAML gives node: x under a, while ColorEncoder (tq's colored output) prints {"a": "x"}.

Proposal: add Any.MarshalJSON and Any.MarshalYAML that encode the wrapped node, and encode null when it is a Go nil node (Any{}, which is the zero value of an absent field, or Any{Node: (*Array)(nil)}), matching how #184 reads such an Any as null.

Value JSON YAML
Any{Node: Map{"k": 1}} {"k":1} k: 1
Any{} / Any{Node: (*Array)(nil)} null null

This changes the output for anyone relying on the {"Node": ...} shape, which cannot be decoded back, so it belongs in the release note.

Dominant language
Go
Stars
7
Forks
2
Avg merge
11h 12m
Merged PRs (30d)
43

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mojatter/tree

All issues in mojatter/tree

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.