Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9257421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:09:48+00:00 2026-06-18T12:09:48+00:00

I am trying to construct JSON object in js. There are couple of posts

  • 0

I am trying to construct JSON object in js. There are couple of posts already about this topic in stack overflow itself. Referred to How do i build JSON dynamically in javascript?. Have to construct JSON exactly something like mentioned in the post.

{
    "privilege": {
        "accesstype": "VIEW",
        "attribute": [
            {
                "code": "contenttype",
                "displayname": "Content type",
                "value": {
                    "valcode": "book_article",
                    "valdisplayName": "Book Article"
                }
            },
            {
                "code": "mime",
                "displayname": "Mime type",
                "value": {
                    "valcode": "xml",
                    "valdisplayName": "Xml"
                }
            }
        ]
    }
}

Follwed the answers in the post and tried this,

var privilege = {};

privilege.attribute[0].code = "contenttype";
privilege.attribute[0].displayname = "Content type";
privilege.attribute[0].value.valcode = "book_article";
privilege.attribute[0].value.valdisplayName = "Book Article";

But getting error as privilege.attribute undefined.

I am not able to figure out where I am going wrong. Assuming there must be some declaration problems. Any light on it would be of great help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:09:49+00:00Added an answer on June 18, 2026 at 12:09 pm

    Try this:

     var privilege = {};
     privilege.attribute = [];
     privilege.attribute[0] = {};
     privilege.attribute[0].code="contenttype";
     privilege.attribute[0].displayname="Content type";
     privilege.attribute[0].value = {};
     privilege.attribute[0].value.valcode="book_article";
     privilege.attribute[0].value.valdisplayName="Book Article";
    

    Have a look at Javascript Object. There is a lot of stuff out there. E.g http://mckoss.com/jscript/object.htm

    Edit: Initialized privilege.attribute[0] = {}; after hint in comment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to construct a customized map in raphaeljs , in this i
I am trying to POST JSON to a WCF service. The json object contains
I'm trying to convert an object, and this object has an ArrayList object has
I am trying to retrieve the raw JSON used to construct a template and
I'm trying to dynamically create object properties for JSON representation of an object. The
I'm trying to convert JSON to C# object using Json.NET. The object looks like
Hey guys so I'm trying to construct some json based on a form submission.
Hi Am trying to parse a json Object with Help of C# DataContractJsonSerializer And
I am trying to pass a JSON object to .getJSON but I keep getting
I'm trying to get objects from a multi-level JSON array. This is the an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.