dzhibas / SublimePrettyJson

Prettify/Minify/Query/Goto/Validate/Lint JSON plugin for Sublime Text 3 & 4
MIT License
2.02k stars 181 forks source link

keep_arrays_single_line: true fails when array itself contains literal `"["` #138

Closed keenahn closed 3 years ago

keenahn commented 3 years ago

Example:

Good:

{"foo":["a","b","c"]}

// After formatting, becomes:

{
  "foo": ["a", "b", "c"]
}

Bad:

{"foo":["[","b","c"]}

// After formatting, becomes:

{
  "foo": [
    "[", "b", "c"]
}

My guess is that there's something happening with your parser where it's looking for the [ symbol

TerminalFi commented 3 years ago

Does this still happen? What version of sublime? What version of Pretty JSON? I can't reproduce this with the latest version of sublime or pretty json

ml0renz0 commented 3 years ago

PrettyJSON 1.1.1 here. I have the same issue. With the following validated JSON:

{
  "calico": {
    "external_routers": [
      {
        "asNumber": "1234",
        "ip": "1.2.3.4",
        "name": "router"
      }
    ]
  }
}

If I Format JSON then it becomes:

{
  "calico":
  {
    "external_routers": [{, "asNumber": "1234", "ip": "1.2.3.4", "name": "router", }]
  }
}

which is clearly Invalid JSON

TerminalFi commented 3 years ago

PrettyJSON 1.1.1 here. I have the same issue. With the following validated JSON:

{
  "calico": {
    "external_routers": [
      {
        "asNumber": "1234",
        "ip": "1.2.3.4",
        "name": "router"
      }
    ]
  }
}

If I Format JSON then it becomes:

{
  "calico":
  {
    "external_routers": [{, "asNumber": "1234", "ip": "1.2.3.4", "name": "router", }]
  }
}

which is clearly Invalid JSON

I see, is the below the expected behavior?

https://user-images.githubusercontent.com/32599364/121284357-94f79a00-c891-11eb-8e18-31f13566bcc2.mp4

TerminalFi commented 3 years ago

Fixed with latest release

shelacek commented 3 years ago

Hello, I think the issue still occurs in version 1.2.1 :-(.

Source JSON:

[{"a": {"b": "c"}}]

After Format JSON command:

[{"a": {,"b": "c"},}]

My user settings only override keep_arrays_single_line:

{
    "keep_arrays_single_line": true
}
TerminalFi commented 3 years ago

https://github.com/dzhibas/SublimePrettyJson/pull/156

TerminalFi commented 3 years ago

Next release fixes this