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 9170879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:05:16+00:00 2026-06-17T16:05:16+00:00

I am trying to create json object for my data. i found that, i

  • 0

I am trying to create json object for my data.

i found that, i can do that using two methods :-

put() and element()

please suggest me, which should be used.

my data is for example :-

key="id" value=32

Thanks in advance !!

  • 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-17T16:05:17+00:00Added an answer on June 17, 2026 at 4:05 pm

    After inspecting the source code it seems that the differences betwee put and element are very minimal.

    The main difference is that put appears to return the object that was previously at the key you entered’s position in the properties map. So if you had a JSONObject structured like so:

    {
        "steve": 4,
        "betty": 5
    }
    

    and executed a command like this:

    Object frank = myJsonObject.put(“steve”, 10);

    The value of frank would now be 4 and the json object would now look like this:

    {
        "steve":10,
        "betty":5
    }
    

    If you had used .element("steve", 10); in the same situation, the object returned from the method is actually your JSONObject instead. The other difference between the two is that the first parameter to the put method is an Object and the first parameter to the element method is a String. The put method simply does a String.valueOf() on the first parameter sent into it and then calls the element method, so basically they both do the same thing, only put is more flexible and technically allows non-string keys that are then converted into strings before calling the element method.

    In a nutshell, they have different parameters and return values, but the put method just calls the element method anyway, so there is not really a difference within the JSONObject, but possibly in your external code.

    I’m guessing jQuery users would prefer to use element due to the similarities to that language in that the method returns the calling object.

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

Sidebar

Related Questions

I'm trying to access data within a JSON object I create using json_decode (based
I'm trying to read data from a service (returns JSON object) and create an
I'm trying to create two method to serialize/deserialize classes using Json.Net and save/load them
Using the jQuery code below, I'm trying to take a JSON object to create
Using the jQuery SelectBox plugin I'm trying to create a JSON object which looks
Whats wrong in below JSON Object definition I am trying to create a new
I'm trying to loop through a number of items, and create a json object.
I am trying to create a json file from a rake task using rabl.
I am trying to add string values in JsonArray and after that create Json
I am trying to create a Google line chart using their API and JSON.

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.