Difference between revisions of "Action: JSON Parse"

Line 3: Line 3:
 
[https://en.wikipedia.org/wiki/JSON 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:
 
[https://en.wikipedia.org/wiki/JSON 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:
  
'''{
+
<pre>
 +
{
 
     "firstName": "Rajesh",
 
     "firstName": "Rajesh",
 
     "lastName": "Kumar",
 
     "lastName": "Kumar",
Line 17: Line 18:
 
         { "type": "home", "number": "7383627627" }
 
         { "type": "home", "number": "7383627627" }
 
     ]
 
     ]
}'''
+
}
 +
</pre>
  
 
This data can be obtained from the following url: https://tools.learningcontainer.com/sample-json.json
 
This data can be obtained from the following url: https://tools.learningcontainer.com/sample-json.json

Revision as of 13:22, 31 March 2022

This action enables strucutred data in JSON format to be parsed into a MacroDroid dictionary variable.

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 with the following format:

dictionary[firstName] = "Rajesh"
dictionary[lastName] = "Kumar"
dictionary[genger] = "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-dictionary with 2 entries
dictionary[phoneNumbers][type] = "home"
dictionary[phoneNumbers][number] = 7383627627