Skip to content

use Set to set a string value then the "" is miss #158

Description

@orchie

i did this
configBytes, err := j.Set(configByte, []byte("http://github.com"), "test")
then the json is
"test":http://github.com,
i try a int like configBytes, err := j.Set(configByte, []byte("2"), "test")
then it works "test":2, because it's' ok
finally i try this
configBytes, err := j.Set(configByte, []byte("\"http://github.com\""), "test")
then it works~
but i feel it's not cool and not frendly to noob,right?

Activity

  1. v-braun commented on Jul 21, 2019

    @v-braun

    Any news on that?

  2. andrewspringman commented on Jul 23, 2019

    @andrewspringman

    +1

  3. fastcity commented on Jul 31, 2019

    @fastcity

    +1

  4. AllenX2018 commented on Mar 19, 2020

    @AllenX2018
    Collaborator

    Set will exactly set what your []byte contains. If you don't like to handle the escape with the slash, you may try a backtick string

    configBytes, err := j.Set(configByte, []byte(`"http://github.com"`), "test")

    output:
    "test":"http://github.com"

  5. buger commented on Jul 28, 2026

    @buger
    Owner

    Implemented in v1.4.0 — use SetString(data, "http://github.com", "test") which auto-quotes and escapes the string value. See: https://github.com/buger/jsonparser/releases/tag/v1.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions