This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 268488

Summary: Formatting a json file brings wrong output and is slow
Product: javascript Reporter: Christian Lenz <chrizzly>
Component: JSONAssignee: arusinha
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 8.2   
Hardware: PC   
OS: Other   
Issue Type: DEFECT Exception Reporter:
Attachments: jsonFormatting problam.
Tabs options
Blank lines options
Spaces option
Wrapping option

Description Christian Lenz 2016-10-12 13:48:49 UTC
Created attachment 162470 [details]
jsonFormatting problam.

Before I switched from 8.1 to 8.2, when I hit my shortcut to format the source inside a JSON file, which has only 2 spaces, everything was fine, it sets the spaces to 3 and did not so much other formatting stuff, if not needed. Now, as you can see in my screen capture, in NB 8.2 first it tooks very long time to format the JSON file and the format is broken as you can see. All options that I set are fine and untouched.


Cheers

Chris
Comment 1 arusinha 2017-04-11 06:15:06 UTC
Not able to reproduce the issue in NetBeans IDE 8.2 (Build 201609300101).
Formatting is happening properly.Please find below the Json file used for the test

{
    "name": "requirements.js",
    "version": "1.0.0",
    "keywords": ["util", "functional", "server", "client", "browser"],
    "description": "A fluent API for enforcing design contracts with automatic message generation.",
    "author": "Gili",
    "contributors": [
    ],
    "dependencies": {

    },
    "devDependencies": {
        "gulp": "^3.9.1"
    }
}


Request you to attach the json file where the bug is reproducible and also the steps to reproduce( if any)
Comment 2 Christian Lenz 2017-05-02 11:32:08 UTC
Same NetBeans version, happens with your json example too.

See my attachments for the JSON options, which I didn't change after updating from 8.1 to 8.2
Comment 3 Christian Lenz 2017-05-02 11:32:46 UTC
Created attachment 164219 [details]
Tabs options
Comment 4 Christian Lenz 2017-05-02 11:33:25 UTC
Created attachment 164220 [details]
Blank lines options
Comment 5 Christian Lenz 2017-05-02 11:33:51 UTC
Created attachment 164221 [details]
Spaces option
Comment 6 Christian Lenz 2017-05-02 11:34:14 UTC
Created attachment 164222 [details]
Wrapping option
Comment 7 Reema 2017-05-05 12:07:57 UTC
Hi, Is the issue related to wrapping of Array items and Objects properties, i.e. with below wrapping option set to Always for all options, Source: Format changes json

{
    "name": "requirements.js",
    "version": "1.0.0",
    "keywords": ["util", "functional", "server", "client", "browser"],
    "description": "A fluent API for enforcing design contracts with automatic message generation.",
    "author": "Gili",
    "contributors": [
    ],
    "dependencies": {"util": "ss", "functional": "ss"},
    "devDependencies": {
        "gulp": "^3.9.1"
    }
}

to 

{
    "name": "requirements.js",
    "version": "1.0.0",
    "keywords": [
        "util",
        "functional",
        "server",
        "client",
        "browser"
    ],
    "description": "A fluent API for enforcing design contracts with automatic message generation.",
    "author": "Gili",
    "contributors": [
    ],
    "dependencies": {
        "util": "ss",
        "functional": "ss"
    },
    "devDependencies": {
        "gulp": "^3.9.1"
    }
}


This behavior seems to correct. As seen in the Tools: Options: Formatting: Preview, with Wrapping set to Always, the Object properties and Array items are added in new lines. Can you try change the respective wrapping option to Never in this case.
Comment 8 Christian Lenz 2017-06-15 08:44:16 UTC
I know, that I didn't change it for months. But ok I tried it and set everything to never. Same problem here. This is package.json:

https://pastebin.com/R59gKdPv

as you can see, that the spaces are 2 and I expect 4. So when I change it to Never and have 4 (which is default for all my languages) the code looks like this again:

https://pastebin.com/tVLs14cM

and it has still 2 spaces for the indentation.
Comment 9 Christian Lenz 2017-06-15 08:46:08 UTC
I think I figured it out, the problem only happens with package.json and bower.json. When I reformat a locale file or a new created file named Tester.json, with the same data from the last comment, everything is fine.
Comment 10 Quality Engineering 2017-07-20 17:51:31 UTC
Integrated into 'main-silver', will be available in build *201707201608* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/21a82d4d570f
User: Arusinha <arusinha@netbeans.org>
Log: #268488 : Fixing formatting for bower.json and package.json files