How-to articles, tricks, and solutions about JSON

How to iterate over a JSONObject?

To iterate over the key/value pairs in a JSONObject, you can use the keys method to get an iterator over the keys in the object, and then use the get method to get the value for each key.

How to JSON Decode a String into an Array with PHP

This is a short guideline that provides comprehensive information on how to decode a JSON string into an array with the help of PHP.

How to make a class JSON serializable

In order to make a class JSON serializable in Python, you need to define two methods: __init__ and to_json.

How to overcome "datetime.datetime not JSON serializable"?

One way to overcome "datetime.datetime not JSON serializable" in Python is to use the json.dumps() method with the default argument, default=str, which converts the datetime object to a string before serializing.

How to parse JSON in Java

To parse a JSON string in Java, you can use the org.json library. This library provides a simple and easy-to-use interface for parsing and manipulating JSON data in Java.

How to parse JSON in Kotlin?

To parse JSON in Kotlin, you can use the JSONObject class from the org.json package.

How to POST JSON data with Python Requests?

You can use the requests library in Python to send a POST request with JSON data.

How to prettyprint a JSON file?

To pretty-print a JSON file in Python, you can use the json module.

How to Print a Circular Structure in a JSON-like Format

In this JavaScript tutorial, you will find useful information about the method that is used to format an object to JSON what contains circular structure.

How to read json file into java with simple JSON library

To read a JSON file into Java using the Simple JSON library, you can use the JSONObject class and the JSONArray class.

How to remove backslash on json_encode() function?

You can use the JSON_UNESCAPED_SLASHES option in the json_encode() function to prevent backslashes from being added to the JSON string.

How to Return JSON from a PHP Script

This short tutorial will represent to you the most effective way of returning JSON from a PHP script.

How to upload a file and JSON data in Postman?

To upload a file and JSON data in Postman, you can follow these steps:

How to use Jackson to deserialise an array of objects

Jackson is a powerful Java library for processing JSON data. You can use Jackson to deserialize an array of objects by following these steps:

Http 415 Unsupported Media type error with JSON

A HTTP 415 Unsupported Media Type error means that the server is unable to process the request because the request entity has a media type that the server does not support. In the context of a JSON request, this means that the server is unable to process

HTTP POST using JSON in Java

To make an HTTP POST request using JSON in Java, you can use the HttpURLConnection class available in the java.net package. Here's an example of how to do it:

HttpServletRequest get JSON POST data

To get JSON POST data from an HttpServletRequest object in Java, you can use the getReader method of the ServletRequest interface to read the request body as a BufferedReader and then use the readLine method to read the data as a string.

Ignoring new fields on JSON objects using Jackson

If you want to ignore new fields on JSON objects when using Jackson, you can use the @JsonIgnoreProperties annotation on your Java object.

Issue reading HTTP request body from a JSON POST in PHP

In PHP, you can read the body of an HTTP request using the file_get_contents('php://input') function.

Jackson with JSON: Unrecognized field, not marked as ignorable

If you are using the Jackson library to parse JSON in Java and you get the error "Unrecognized field, not marked as ignorable", it means that you are trying to parse a JSON object that has a field that is not recognized by your Java object.

json_decode to custom class

In PHP, you can use the json_decode() function to convert a JSON string into a PHP object or array.

JSON_ENCODE of multidimensional array giving different results

JSON_ENCODE is a function that converts a PHP data structure, such as an array, into a JSON (JavaScript Object Notation) string.

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

The error message "JSONDecodeError: Expecting value: line 1 column 1 (char 0)" typically occurs when you are trying to parse a string as JSON, but the string is not in a valid JSON format.

Only using @JsonIgnore during serialization, but not deserialization

If you want to use the @JsonIgnore annotation to ignore a field during serialization but not during deserialization, you can use the @JsonIgnoreProperties annotation and set its writeOnly property to true.

Parsing JSON Object in Java

To parse a JSON object in Java, you can use the org.json library.