pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

Json

Example

JSON is a lightweight data interchange format, and here's how to use JSON functions

from m5stack import *
from m5ui import *
from uiflow import *
from libs.json_py import *
import json

date = None

date = py_2_json({'author':'M5Stack','people':100,'device':'CoreS3','number':5})
print(json.dumps(date))
print(get_json_keys(date))
print(get_json_key(date, 'number'))
print(get_json_values(date))
print(get_json_keys_len(date))
set_json_elements(date, 'people', 101)
set_json_elements(date, 'devicetow', 'core2')
delete_json_elements(date, 'number')
print(json.dumps(date))
print(json.loads('{"string":"stack","number":100}'))

API

print(json.dumps(date))
  • Convert (serialize) a Python object (such as a list or dictionary) into a JSON-formatted string
set_json_elements(date, 'devicetow', 'core2')
  • Add a key-value pair to a JSON object
date = py_2_json({'author':'M5Stack','people':100,'device':'CoreS3','number':5})
  • Create a JSON object using key-value pairs
delete_json_elements(date, 'number')
  • Delete a key-value pair from a JSON object based on the key
print(get_json_key(date, 'number'))
  • Get the value of a specified key from a JSON object
print(get_json_keys(date))
  • Get all keys from a JSON object and return them as a list
print(get_json_keys_len(date))
  • Get the length of a JSON object (note: for dictionaries, it's the number of key-value pairs)
print(get_json_values(date))
  • Get all values from a JSON object and return them as a list
set_json_elements(date, 'people', 101)
  • Set the value of a corresponding key in a JSON object
print(json.loads('{"string":"stack","number":100}'))
  • Parse a string containing a valid JSON object
On This Page