function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
K S R PAVAN KUMARK S R PAVAN KUMAR 

json parsing in lwc

Iam trying to parse json below and access values from javascript. can anybody help me with the code.
json={ 
     "ShareRecords": [],
        "RecordOwnership": {
            "Ownerofrecord": "false"
        },
        "QueryDetails": {
            "UserName": "Wendy West",
            "ObjectName": "SBQQ__Quote__c"
        },
        "ProfileSystemPermissions": {
            "ViewAllData": "false",
            "ProfileSystemPermissionId": "0PS5w000002S7qAGAS",
            "ProfileName": "*Sales",
            "ModifyAllData": "false",
            "hasAccess": "NoAccess"
        },
        "ProfileObjectPermissions": [
            {
                "ViewAllRecords": "true",
                "ProfileObjectPermissionId": "1105w00001Pw2xmAAB",
                "PermissionRead": "true",
                "PermissionName": "X00eo0000000f9DDAAY",
                "PermissionEdit": "true",
                "PermissionDelete": "true",
                "PermissionCreate": "true",
                "ModifyAllRecords": "true",
                "hasAccess": "FullAccess"
            }
        ],
        "PlatformFinalComputedAccess": {
            "MaxAccessLevel": "All",
            "HasTransferAccess": "true",
            "HasReadAccess": "true",
            "HasEditAccess": "true",
            "HasDeleteAccess": "true",
            "HasAllAccess": "true"
        },
        "PermissionSetSystemPermissions": [
            {
                "ViewAllData": "false",
                "PermissionSetSystemPermissionId": "0PS5w000002S7qAGAS",
                "PermissionSetName": "X00eo0000000f9DDAAY",
                "ModifyAllData": "false",
                "hasAccess": "NoAccess"
            },
            {
                "ViewAllData": "false",
                "PermissionSetSystemPermissionId": "0PS5w000002S7rtGAC",
                "PermissionSetName": "Pardot",
                "ModifyAllData": "false",
                "hasAccess": "NoAccess"
            },
            {
                "ViewAllData": "false",
                "PermissionSetSystemPermissionId": "0PS5w000002S7sYGAS",
                "PermissionSetName": "Sales_Cloud_Einstein_PSL",
                "ModifyAllData": "false",
                "hasAccess": "NoAccess"
            },
            {
                "ViewAllData": "false",
                "PermissionSetSystemPermissionId": "0PS5w000002S7t4GAC",
                "PermissionSetName": "EinsteinAnalyticsPlusUserPSL",
                "ModifyAllData": "false",
                "hasAccess": "NoAccess"
            },
            {
                "ViewAllData": "false",
                "PermissionSetSystemPermissionId": "0PS5w000002S7tDGAS",
                "PermissionSetName": "Motivate_Standard_User",
                "ModifyAllData": "false",
                "hasAccess": "NoAccess"
            },
            {
                "ViewAllData": "false",
                "PermissionSetSystemPermissionId": "0PS5w000002S7tEGAS",
                "PermissionSetName": "Align_Standard_User",
                "ModifyAllData": "false",
                "hasAccess": "NoAccess"
            },
            {
                "ViewAllData": "false",
                "PermissionSetSystemPermissionId": "0PS5w000002S7tFGAS",
                "PermissionSetName": "Perform_Standard_User",
                "ModifyAllData": "false",
                "hasAccess": "NoAccess"
            },
            {
                "ViewAllData": "false",
                "PermissionSetSystemPermissionId": "0PS5w000002S7tKGAS",
                "PermissionSetName": "Lightning_Dialer",
                "ModifyAllData": "false",
                "hasAccess": "NoAccess"
            }
        ],
        "PermissionSetObjectPermissions": [
            {
                "ViewAllRecords": "true",
                "PermissionSetObjectPermissionId": null,
                "PermissionRead": "true",
                "PermissionName": "X00eo0000000f9DDAAY",
                "PermissionEdit": "true",
                "PermissionDelete": "true",
                "PermissionCreate": "true",
                "ModifyAllRecords": "true",
                "hasAccess": "FullAccess"
            }
        ],
        "OWDAccessLevel": {
            "OWDAccessLevelId": "000000000000000AAA",
            "InternalSharingModel": "ReadWrite",
            "ExternalSharingModel": "Private"
        },
        "GroupMembership": [
            {
                "Type": "Regular",
                "Name": "SalesReps",
                "GroupId": "00G5w000007NK9CEAW"
            }
        ] 
    };

// Converting JSON object to JS object
 obj = JSON.parse(json);
 QDetails=obj.QueryDetails.UserName;
 console.log(QDetails);
 

}

But when component is deployed , it says json is not defined
David Zhu 🔥David Zhu 🔥
You may need to change line 1 and line 124 to declare the variable using let or var.

Line 1:  let json={

Line 124: let obj = JSON.parse(json);
K S R PAVAN KUMARK S R PAVAN KUMAR
Hi David, I tried as you said but it didn't work. Getting same error when deploying component in app builder
Ankit Yadav 90Ankit Yadav 90
Double parsing worked for me.
JSON.parse(JSON.parse(json))
sanjayrs23sanjayrs23
Prasing twice worked, but not clear why you need parsing again. Thanks Ankit