Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Deleting and Adding a Key corrupts the JSON #209

Copy link
Copy link

Description

@bandikishores
Issue body actions

Hi,

If we delete a name & add it back, the JSON is corrupted. Its Partially formed and values at the end of the JSON are truncated.

Code:

package main

import (
	"fmt"
	"github.com/buger/jsonparser"
)

var jsonByteGlobal []byte = []byte(
	`{
		"person": {
		  "fullName": "Leonid Bugaev"
		},
		"company": {
		   "name": "Acme"
		}
	  }`)

func main() {
	jsonByteArray := jsonByteGlobal

	jsonByteArray = jsonparser.Delete(jsonByteArray, "person", "fullName")
	fmt.Printf("After Deletion : %s\n", string(jsonByteArray))

	jsonparser.Set(jsonByteArray, []byte(`"Kishore Bandi"`), "person", "fullName")
	fmt.Printf("After Addition : %s\n", string(jsonByteArray))
}

Output:

After Deletion : {
		"person": {
		},
		"company": {
		   "name": "Acme"
		}
	  }
After Addition : {
		"person": {"fullName":"Kishore Bandi"},
		"company": {

In above output, the company part of the JSON got truncated when we tried to add "person"."fullName"

Playground : https://play.golang.org/p/y4cE3UaGoR7

Reactions are currently unavailable

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

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.