Skip to content

How to publish and consume JSON data? #5554

Answered by neilalexander
kharabela asked this question in Q&A
Discussion options

You must be logged in to vote

JetStream doesn't care about strings vs encoded formats, you just provide a some bytes.

Therefore just encode your JSON before you publish it:

foo := struct{
  Bar string `json:"bar"`
}{
  Bar: "baz",
}

j, err := json.Marshal(foo)
if err != nil {
  ...
}

// "j" is []byte here

_, err = js.PublishAsync("subject", j)
if err != nil {
  ...
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kharabela
# for free to join this conversation on GitHub. Already have an account? # to comment
Category
Q&A
Labels
None yet
2 participants