Found 204 Articles for JSON

How to convert HASHMAP to JSON using GSON in Android?

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

1K+ Views

GSON is java library, It is used to convert OBJECT to JSON and JSON to Object. Internally it going to work based on serialization and deserialization.This example demonstrates how to convert HASHAMP to JSON using GSON library.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code in build.gradle.apply plugin: 'com.android.application' android {    compileSdkVersion 28    defaultConfig {       applicationId "com.example.andy.myapplication"       minSdkVersion 15       targetSdkVersion 28       versionCode ... Read More

How to store data in MySQL as JSON?

George John
Updated on 30-Jul-2019 22:30:23

299 Views

We can store data in MySQL as JSON with the help of JSON data type. The following is an example. Let us now create a table. mysql> CREATE table JsonAsMySQLDemo -> ( -> id int, -> name varchar(100), -> PageDemo JSON, -> eventInfo JSON -> ); Query OK, 0 rows affected (0.67 sec) Storing records into JSON data type. mysql> INSERT into JsonAsMySQLDemo values -> ( -> 1, ... Read More

Map.delete() function in JavaScript

karthikeya Boyini
Updated on 25-Jun-2020 12:14:47

5K+ Views

The delete() function of Map object accepts a string representing the key of an element of a map and deletes from the current Map object. This function returns true if the specified key exists in the map object else it returns false.SyntaxIts Syntax is as followsmapVar.delete()Example Live Demo    JavaScript Example           var mapVar = new Map();       mapVar.set('1', 'Java');       mapVar.set('2', 'JavaFX');       mapVar.set('3', 'HBase');       mapVar.set('4', 'Neo4j');       var map = mapVar.delete('4');       document.write("Size of the map object: "+mapVar.size);   ... Read More

JSON. stringify( ) function in JavaScript

karthikeya Boyini
Updated on 25-Jun-2020 12:03:07

254 Views

The stringify() function of a JSON object accepts a JSON string, and constructs an object based on the given text and, returns it.SyntaxIts Syntax is as followsJson.stringify();Example Live Demo    JavaScript Example           var jsonSample = '{Tutorial: Java, Version:8}';       jsonObj = JSON.stringify(jsonSample);       document.write(jsonObj);     Output"{Tutorial: Java, Version:8}"

How to generate JSON output using Python?

karthikeya Boyini
Updated on 05-Mar-2020 10:16:33

2K+ Views

The json module in python allows you to dump a dict to json format directly. To use it,Exampleimport json my_dict = {    'foo': 42,    'bar': {       'baz': "Hello",       'poo': 124.2    } } my_json = json.dumps(my_dict) print(my_json)OutputThis will give the output −'{"foo": 42, "bar": {"baz": "Hello", "poo": 124.2}}'You can also pass indent argument to prettyprint the json. exampleimport json my_dict = {    'foo': 42,    'bar': {       'baz': "Hello",       'poo': 124.2    } } my_json = json.dumps(my_dict, indent=2) print(my_json)OutputThis will give the output −{    "foo": 42,    "bar":    {       "baz": "Hello",       "poo": 124.2    } }

Escaping/encoding single quotes in JSON encoded HTML5 data attributes

George John
Updated on 30-Jul-2019 22:30:22

4K+ Views

To escape single quotes, use json_encode() to echo arrays in HTML5 data attributes.printf('', htmlspecialchars(json_encode(array('html5', ...)), ENT_QUOTES, 'UTF-8'));Or you can also using built-injson_encode(array('html5', ...), JSON_HEX_APOS)

How I can dump a Python tuple in JSON format?

Niharika Aitam
Updated on 29-May-2025 11:29:51

1K+ Views

JSON can be abbreviated as JavaScript Object Notation. It means a script of a text file in a programming language to transfer and store the data. It is supported by the Python programming language using a built-in package named JSON. Its text is given in the quoted string format, which contains a key and value within the curly braces{}, which looks like a dictionary. To access a JSON document using Python, we have to use the JSON package. In this package, we have a method named dumps(), which is used to convert the Python tuple objects into the Java objects. ... Read More

How I can create Python class from JSON object?

Rajendra Dharmkar
Updated on 16-Jun-2020 08:38:28

1K+ Views

We can use python-jsonschema-objects which is built on top of jsonschema.The python-jsonschema-objects provide an automatic class-based binding to JSON schemas for use in Python.We have a sample json schema as followsschema = '''{     "title": "Example Schema",     "type": "object",     "properties": {         "firstName": {             "type": "string"         },         "lastName": {             "type": "string"         },         "age": {             "description": "Age in years", ... Read More

How to convert Python date in JSON format?

Rajendra Dharmkar
Updated on 02-Nov-2023 01:50:21

3K+ Views

There is no standard JSON format for dates. Although JavaScript does have a standard date format that is human readable, sorts correctly, includes fractional seconds(which can help re-establish chronology) and  conforms to ISO 8601. You can convert a Python date to the JS date format using the strftime function and deserialize it using the client that needs this date. To get an ISO 8601 date in string format in Python 3, you can simply use the isoformat function. It returns the date in the ISO 8601 format. For example, if you give it the date 31/12/2017, it'll give you the ... Read More

What are the differences between json and simplejson Python modules?

Rajendra Dharmkar
Updated on 30-Sep-2019 08:59:36

891 Views

json is simplejson, added to the stdlib. But since json was added in 2.6, simplejson has the advantage of working on more Python versions (2.4+).simplejson is also updated more frequently than Python. Although they are the same, the version included in the stdlib doesn't include the latest optimizations. So if you need (or want) the latest version, it's best to use simplejson itself, if possible.A good practice, is to use one or the other as a fallback. For example,try: import simplejson as json except ImportError: import json

Advertisements