Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected tailing comma #36

Open
g-chao opened this issue May 18, 2024 · 0 comments
Open

Unexpected tailing comma #36

g-chao opened this issue May 18, 2024 · 0 comments

Comments

@g-chao
Copy link

g-chao commented May 18, 2024

Suppose we have the following JS code

const jju = require('jju');
const rawJsonString = `{
  "entry1": [
    {
      "path1": "path1"
    }
  ],
  "entry2": "value2"
}
`
const jsonObject = jju.parse(rawJsonString);

// add new entries to object
jsonObject["entry3"] = {
  "value2": {
    "2": true
  },
  "value3": {
    "3": true
  }
}

// call the update API
const newRawJsonString = jju.update(rawJsonString, jsonObject);

// print out to check the value
console.log(newRawJsonString);

Execute it, it will see following output

{
  "entry1": [
    {
      "path1": "path1"
    }
  ],
  "entry2": "value2",
  "entry3": {
    "value2": {
      "2": true
    },
    "value3": {
      "3": true
    }
  }
}

Which is correct.

Now, let's change the rawJsonString in the code, the only difference, is now the entry1 has two elements

const jju = require('jju');
const rawJsonString = `{
  "entry1": [
    {
      "path1": "path1"
    },
    {
      "path2": "path2"
    }
  ],
  "entry2": "value2"
}
`
const jsonObject = jju.parse(rawJsonString);

// add new entries to object
jsonObject["entry3"] = {
  "value2": {
    "2": true
  },
  "value3": {
    "3": true
  }
}

// call the update API
const newRawJsonString = jju.update(rawJsonString, jsonObject);

// print out to check the value
console.log(newRawJsonString);

Execute it, it will see following output

{
  "entry1": [
    {
      "path1": "path1"
    },
    {
      "path2": "path2"
    }
  ],
  "entry2": "value2",
  "entry3": {
    "value2": {
      "2": true, // <--- this tailing comma should not be here
    },
    "value3": {
      "3": true, // <--- this tailing comma should not be here
    }, // <--- this tailing comma should not be here
  }
}

Which is not correct, you can see there are unexpected tailing commas on the new added entries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant