Skip to content

Add JSON representation of KeyValueEntry #1969

@justenstall

Description

@justenstall

Proposed change

Update the implementation of jetstream.KeyValueEntry to implement json.Marshaler.

Example implementation to add to the kve type in jetstream/kv.go:

func (e *kve) MarshalJSON() ([]byte, error) {
	return json.Marshal(map[string]any{
		"bucket":   e.Bucket(),
		"key":      e.Key(),
		"value":    string(e.Value()),
		"revision": e.Revision(),
		"created":  e.Created(),
		"delta":    e.Delta(),
		"op":       e.Operation().String(),
	})
}

Use case

Related to nats-io/natscli#1552.

The motivation is to provide a standard JSON representation of the KeyValueEntry information, which would be useful for structured logging and for JSON output from the NATS CLI.

Contribution

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThe defect or proposal as been acceptedproposalEnhancement idea or proposal

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions