Serialize multidimensional form data into a JSON object-array to work with application/json
Date : March 29 2020, 07:55 AM
Hope this helps I had the same problem but this package did the trick: jQuery Serialize ObjectIt's easy to use, just call this on your form (after loading the script) $('form#contact').serializeJSON(); // to get the form as a JS object
|
PHP - Appending new JSON data to existing multidimensional JSON
Tag : php , By : user142345
Date : March 29 2020, 07:55 AM
will help you This should help you out. If you have more than one channel you'll need the index of the channel so you can add the new post to it's feed. $json = '[
{
"channel": "RSS Channel",
"description": "RSS Description",
"publish_date": "Wed, 17 Feb 2016 16:21:30 +0000",
"last_build_date": "Wed, 17 Feb 2016 16:21:30 +0000",
"generator": "A Human",
"link": "mysite.com",
"atom_link": "http://example.com/index.rss",
"feed": [
{
"post_id": "3",
"title": "Some RSS feed 3...",
"publish_date": "Wed, 17 Feb 2016 16:30:55 +0000",
"link": "http://example.com/#post3",
"guid": "http://example.com/#post3",
"author": "WhoAmI?",
"content": "More!"
},
{
"post_id": "2",
"title": "Some RSS feed 2...",
"publish_date": "Wed, 17 Feb 2016 16:30:55 +0000",
"link": "http://example.com/#post3",
"guid": "http://example.com/#post3",
"author": "WhoAmI?",
"content": "More!"
},
{
"post_id": "1",
"title": "Some RSS feed 1...",
"publish_date": "Wed, 17 Feb 2016 16:30:55 +0000",
"link": "http://example.com/#post3",
"guid": "http://example.com/#post3",
"author": "WhoAmI?",
"content": "More!"
}
]
}
]';
$data = json_decode($json); // converts json to php array of channel objects
$post_title = "Post test";
$post_content = "Yay, it worked! :D";
$post_id = count($data[0]->feed) + 1;
$post_link = $domain . "/#" . $post_id;
$post_guid = $domain . "/#" . $post_id;
$post_author = "Someone";
$new_postArray = array('post_id' => $post_id, 'title' => $post_title, 'publish_date' => $today, 'link' => $post_link, 'guid' => $post_guid, 'author' => $post_author, 'content' => $post_content); // Array of new post content.
// Add new post to BEGINNING of feed
$data[0]->feed = $new_postArray + $data[0]->feed;
$encoded_json = json_encode($data, JSON_PRETTY_PRINT);
exit($encoded_json);
?>
|
jQuery multidimensional JSON array with different data in the same JSON?
Date : March 29 2020, 07:55 AM
this one helps. Since all of your items have an entities property but only some of those entities have a media property, you should check for the existence of that media property and all of its sub-properties down to media_url_https before using it to build your html string, ie: if (item.entities.media
&& item.entities.media.length
&& item.entities.media[0].media_url_https) {
// code to add image to html string
}
|
Using LOAD DATA to import JSON data and specify date data type on import
Date : March 29 2020, 07:55 AM
this will help I understand that you are using MySQL 8.0.4 or higher because you are using JSON_TABLE() function. One option is to use STR_TO_DATE function: SELECT
`test`.`buyer`,
STR_TO_DATE(`test`.`date`, '%M %D %Y') `date`,
`test`.`id`,
`test`.`item_desc`
FROM
`example_table`,
JSON_TABLE(
`json_data`,
'$.sale_list[*]' COLUMNS(
`buyer` VARCHAR(40) PATH '$.buyer',
`date` VARCHAR(40) PATH '$.date',
`id` VARCHAR(40) PATH '$.id',
`item_desc` VARCHAR(40) PATH '$.item_desc'
)
) `test`;
LOAD DATA INFILE '/path/to/file/sample.json'
INTO TABLE `example_table` (@`json`)
SET `json_data` =
JSON_REPLACE(
@`json`,
'$.sale_list[0].date',
LEFT(
STR_TO_DATE(
JSON_UNQUOTE(
JSON_EXTRACT(
@`json`,
'$.sale_list[0].date'
)
),
'%M %D %Y %H:%i:%s'),
10)
);
|
MagicalRecords import data from JSON / NSDictionary. Import relationships
Date : March 29 2020, 07:55 AM
|