The "opposite" of JSON.stringify is JSON.parse. It will return you a JavaScript object with that structure. To get your strings, you'd want to do:

var data = JSON.parse("... your string ...");
data.results.map(function(obj) { return obj["value"]; });
Answer from Michael Zhang on Stack Overflow
🌐
W3Schools
w3schools.com › js › js_json_stringify.asp
JavaScript JSON.stringify()
JSON.stringify() can convert all JavaScript values that JSON supports.
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 22890168 › extract-json-stringifydata › 22890320
php - extract json.stringify(data) - Stack Overflow
<textarea style="width: 100%; height: 300px;" id="request_json"> { "requestType":"TourListRequest", "data":{ "ApiKey":"12345", "ResellerId":"999", "SupplierId":"999", "ExternalReference":"12345", "Timestamp":"2013-12-10T13:30:54.616+10:00", "Extension":{ "any":{ } }, "Parameter":{ "Name":{ "0":" " }, "Value":{ } } } } </textarea> <script> function SubmitAPI() { var sendInfo = { JSON : $('#request_json').val(), URL : $('#supplier_api_endpoint_JSON_Tour_List').val(), Type : 'JSON Tour List' }; $('#response_json').html("Calling API..."); $.ajax({ url: 'post_JSON.php', type: "POST", data: JSON.stringify(sendInfo), // send the string directly success: function(response){ var obj = jQuery.parseJSON( response ); $('#response_json').html(response); $('#response_validation').html( obj.json_valid ); }, error: function(response) { $('#response_json').html(response); } }); } </script>
🌐
ServiceNow Community
servicenow.com › community › developer-blog › fetch-value-from-json › ba-p › 2282127
Fetch value from JSON - ServiceNow Community
July 13, 2023 - Let’s see an example how to navigate to get the value of particular key by parsing the JSON but before that it’s always good to Format the JSON in pretty format (if required) for better user readability and that can be done by using JSON.stringify(variable name, undefined, 2), that gives ...
🌐
freeCodeCamp
freecodecamp.org › news › json-stringify-example-how-to-parse-a-json-object-with-javascript
JSON Stringify Example – How to Parse a JSON Object with JS
January 5, 2021 - And just like that, you've parsed incoming JSON with fetch and used JSON.stringify() to convert a JS object literal into a JSON string.
Top answer
1 of 5
3

You need to use JSON.parse(), to make it a regular JavaScript object again.

What JSON.stringify() does is, as the name implies, make it a string. That is just a regular string, that represents JSON data. It doesn't magically have the JSON data properties.

Furthermore serializeArray() returns an array of {name: ..., value: ...} objects. If you didn't turn it into a JSON string, the result still could not easily be accessed by doing formConfig.client_id. You'd have to loop through the formConfig array, to find the desired name/value pair.

From the looks of it, you don't need to turn the JavaScript object into JSON at all, if you are just going to use it in the same script (unless you are going to send the JSON string somewhere else perhaps).


Based on OP's comments, I'm assuming OP just want to access a particular form element's value. Using jQuery, this can easily be accomplished with:

// get the value of the client_id element (assuming it's an input element)
var client_id = $( '#bookingform input[name="client_id"]' ).val();
// call the function
confirmBooking( '.config_batteri', client_id, "Yes", "No" );

If you want to have an object with all the form values, have a look at the answers in this question.

2 of 5
1

Do this:

var jsonStr = '[{"name":"client_id","value":"1"},
                {"name":"consignee_id","value":""},
                {"name":"client","value":"DAKO"},
                {"name":"model","value":"2"},
                {"name":"type","value":"2"},
                {"name":"temperatur","value":"2"},
                {"name":"shipper_labels","value":"1"},
                {"name":"batteri_labels","value":"1"},
                {"name":"batteri_number","value":"2222"},
                {"name":"pickup","value":"April 27, 2017 18:25"},
                {"name":"intern_marks","value":"fdsfads"},
                {"name":"extern_marks","value":"sadsfdsf"},
                {"name":"consignee","value":""},
                {"name":"marks","value":""}]';

var obj = JSON.parse(jsonStr);
var val = obj[0].value;

The reason you can't do obj[0].name is because your parsed JSON object has a collection of objects, where the first object has this structure:

{
    name:"client_id",
    value:"1"
}

So, you have to access it using obj[0].value NOT obj[0].name as it would give you client_id.

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › JSON › stringify
JSON.stringify() - JavaScript - MDN Web Docs
If it is a number, successive levels in the stringification will each be indented by this many space characters. If it is a string, successive levels will be indented by this string. Each level of indentation will never be longer than 10. Number values of space are clamped to 10, and string values are truncated to 10 characters. ... JSON.stringify({}); // '{}' JSON.stringify(true); // 'true' JSON.stringify("foo"); // '"foo"' JSON.stringify([1, "false", false]); // '[1,"false",false]' JSON.stringify([NaN, null, Infinity]); // '[null,null,null]' JSON.stringify({ x: 5 }); // '{"x":5}' JSON.string
🌐
Online Tools
onlinetools.com › json › stringify-json
Stringify JSON – Online JSON Tools
For example, it can convert a JavaScript expression, a JSON object, a string with special characters, and a larger text with newlines into a compactly stringified JSON string. It works in the browser and uses the native JSON.stringify() function to get the job done. This function converts elementary values (strings, numbers, constants, booleans), objects, and arrays to a quoted string.
🌐
Execute Program
executeprogram.com › courses › modern-javascript › lessons › json-stringify-and-parse
Modern JavaScript: JSON Stringify and Parse
Learn programming languages like TypeScript, Python, JavaScript, SQL, and regular expressions. Interactive with real code examples.
🌐
W3Schools
w3schools.com › JSREF › jsref_stringify.asp
JavaScript JSON stringify() Method
The JSON.stringify() method converts JavaScript objects into strings. When sending data to a web server the data has to be a string. The numbers in the table specify the first browser version that fully supports the method. ... /*replace the value of "city" to upper case:*/ var obj = { "name":"John", "age":"39", "city":"New York"}; var text = JSON.stringify(obj, function (key, value) { if (key == "city") { return value.toUpperCase(); } else { return value; } }); Try it Yourself »