You could use json_to_map()
to turn your json into a dictionary and then get the value of 'creation_time'
by using map_get()
to search for that key. Here an example, (I made a full json out of your example, copying a random one from the web):
map_get(json_to_map('
{
"crs":{
"type":"name",
"properties":{
"name":"[EPSG:code]"
}
},
"license":"[license info]",
"mapname":"[name of the map]",
"map_long_name":"[despription of the map]",
"map_short_name":"[short name]",
"map_abstract":"[abstract of the map]",
"creation_time":"[timestamp]",
"type":"FeatureCollection",
"features":[
{
"type":"Feature",
"properties":{
"name":"codecentric AG",
"address":"Hochstr. 11",
"marker-color":"#008800",
"marker-symbol":"commercial"
},
"geometry":{
"type":"Point",
"coordinates":[
7.0069,
51.1623
]
}
}
]
}
'),'creation_time')
This example will return '[timestamp]'
. Depending on how you access this data, you need to hand it over as string to this function.
I could not find a possibility to load data from external urls via expressions. So I created this custom function:
from qgis.core import *
from qgis.gui import *
import urllib.request
import urllib
import json
@qgsfunction(args='auto', group='Custom')
def jsonfromurl(url, feature, parent):
header = {"accept":"application/json"}
request = urllib.request.Request(url)
response = urllib.request.urlopen(request)
response_data = response.read()
encoding = response.info().get_content_charset('utf-8')
data = json.loads(response_data.decode(encoding))
#txt = json.dumps(data) #uncomment this line to receive data as string. also change next line to: return txt
return data
It basically accesses the json content from a given url. My test url is http://api.plos.org/search?q=title:DNA
. In case your url does not return a json by default, you may need adjust the second line to request = urllib.request.Request(url,header)
. In case you want to receive your json as string, uncomment the second last line and change the last one to return txt
.
Example usage: map_get(jsonfromurl('http://api.plos.org/search?q=title:DNA'),'response')
, so in your case maybe map_get(jsonfromurl('yoururls'),'creation_time')
.