Difference between revisions of "Action: JSON Parse"

Tags: Mobile web edit Mobile edit
Line 27: Line 27:
 
dictionary[firstName] = "Rajesh"
 
dictionary[firstName] = "Rajesh"
 
dictionary[lastName] = "Kumar"
 
dictionary[lastName] = "Kumar"
dictionary[genger] = "man"
+
dictionary[gender] = "man"
 
dictionary[age] = 24
 
dictionary[age] = 24
 
dictionary[address] = sub-dictionary with 4 entries
 
dictionary[address] = sub-dictionary with 4 entries
Line 34: Line 34:
 
dictionary[address][state] = "GJ"
 
dictionary[address][state] = "GJ"
 
dictionary[address][postalCode] = "394221"
 
dictionary[address][postalCode] = "394221"
dictionary[phoneNumbers] = sub-dictionary with 2 entries
+
dictionary[phoneNumbers] = sub-array with 2 entries
 +
dictionary[phoneNumbers][0] = sub-dictionary with 2 entries
 
dictionary[phoneNumbers][type] = "home"
 
dictionary[phoneNumbers][type] = "home"
 
dictionary[phoneNumbers][number] = 7383627627
 
dictionary[phoneNumbers][number] = 7383627627
 
</pre>
 
</pre>
 
You can then use the values of interest from the dictionary in your macros, for example to populate a weather summary from a weather API or similar.
 
You can then use the values of interest from the dictionary in your macros, for example to populate a weather summary from a weather API or similar.

Revision as of 16:19, 7 September 2023

This action enables structured data in JSON format from a String variable to be parsed into a MacroDroid Dictionary variable. It will typically be used in conjunction with the HTTP Request action which will save the JSON data into a string ready to be parsed.

JSON data is a widely used format by many Web APIs to provide data in a structured/nested format. A typical example of such data is below:

{
    "firstName": "Rajesh",
    "lastName": "Kumar",
    "gender": "man",
    "age": 24,
    "address": {
        "streetAddress": "126 Udhna",
        "city": "Surat",
        "state": "GJ",
        "postalCode": "394221"
    },
    "phoneNumbers": [
        { "type": "home", "number": "7383627627" }
    ]
}

This data can be obtained from the following url: https://tools.learningcontainer.com/sample-json.json

This data will be parsed into a dictionary variable in MacroDroid and end up populated with the data below:

dictionary[firstName] = "Rajesh"
dictionary[lastName] = "Kumar"
dictionary[gender] = "man"
dictionary[age] = 24
dictionary[address] = sub-dictionary with 4 entries
dictionary[address][streetAddress] = "126 Udhna"
dictionary[address][city] = "Surat"
dictionary[address][state] = "GJ"
dictionary[address][postalCode] = "394221"
dictionary[phoneNumbers] = sub-array with 2 entries
dictionary[phoneNumbers][0] = sub-dictionary with 2 entries
dictionary[phoneNumbers][type] = "home"
dictionary[phoneNumbers][number] = 7383627627

You can then use the values of interest from the dictionary in your macros, for example to populate a weather summary from a weather API or similar.