I've been doing a lot of research and had several discussions in chat about learning to take a JSON feed and add the content to a post in WordPress.
In the past I would create a page template and through the setting's admin panel create a form field for a particular API's key and when the template was used it would call the JSON into a folder and loop through the results on a single page with links to the site it originated from. Now I would like to learn how take the JSON and add it to the database to be used in a post.
Research and discussions in chat have resulted several tutorials and Q&As on the subject such as:
- Using the WP-API to Fetch Posts
- how do i convert this JSON array to html then create a WordPress post with the collected data?
- simple wp_insert_post example
- wp_insert_post with a form
- Programmatically Create a Post in WordPress
Importing the data I was able to find:
- Making Remote Requests with wp_remote_get
- Import JSON feed to Wordpress
- How to import external JSON and display in php
- JSON decoding from a URL
However, I've always been taught when inputting data it should always be considered as bad input and should be tested and cleaned. When researching on sanitizing input I did run across:
Though I didn't really see anything discussing if JSON should be sanitized and when I was looking for a hook I didn't see anything. So this leads me to my question. When calling a JSON feed from a third party source should the JSON be sanitized before adding it to the database and if so does WordPress have a built in way to do it? When I researched sanitize JSON I didn't find anything built in WordPress that could sanitize the JSON.