JMESPath - features[?geometry.type == `LineString`]
// Filter function for https://jsoneditoronline.org/ and recursive filter names
function query(data) {
return _.chain(data)
.mapValues(value => {
if (_.isPlainObject(value)) {
return filterKeys(value, ['name','mess']);
}
return value;
})
.pickBy(obj => _.isPlainObject(obj) && Object.keys(obj).length > 0)
.map( (item) => item["object Object"])
.value();
}
function filterKeys(obj, wildcards) {
const result = {};
const filter = (val, key, parent) => {
if (_.isPlainObject(val)) {
_.forEach(val, filter);
}
if (_.some(wildcards, wildcard => _.includes(key, wildcard))) {
_.set(result, `${parent}.${key}`, val);
}
};
filter(obj, 'root', 'root');
return result;
}
-
Chrome console load library
async function loadScript(url) {
let response = await fetch(url);
let script = await response.text();
eval(script);
}
let scriptUrl = 'https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.min.js'
loadScript(scriptUrl);
Chrome console save method
(function(console){
console.save = function(data, filename){
if(!data) {
console.error('Console.save: No data')
return;
}
if(!filename) filename = 'console.json'
if(typeof data === "object"){
data = JSON.stringify(data, undefined, 4)
}
var blob = new Blob([data], {type: 'text/json'}),
e = document.createEvent('MouseEvents'),
a = document.createElement('a')
a.download = filename
a.href = window.URL.createObjectURL(blob)
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':')
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
a.dispatchEvent(e)
}
})(console)
Process obect
var sorted = vpns.reduce(
(result, vpn) => {
Object.keys(vpn).reduce((c, k) => (c[k.toLowerCase()] = vpn[k], c), {});
result[vpn.Login.toLowerCase()]=vpn;
return result;
},
[]);
var sorted = vpns.reduce(
(result, vpn) => {
var key = vpn.Login.toLowerCase(); //first property: a, b, c
result[key] = vpn;
return result;
},
{});
Manipulating data
// Yandex maps example
"{"type":"Feature","id":10,"geometry":{"type":"Point","coordinates":[56.257111,58.012524]},"properties":{"description":"Россия, Пермь, улица Луначарского, 4","iconCaption":"3102 (1771 чел.)","marker-color":"#ed4543"}}"
{
type: b.type,
id: b.id,
geometry: b.geometry,
type: b.geometry.type,
long: b.geometry.coordinates[0] ,
lat: b.geometry.coordinates[1] ,
properties: b.properties,
description: b.properties.description,
iconCaption: b.properties.iconCaption,
markercolor: b.properties.marker-color
}
b=a.features.map( (b) => { return {
type: b.type,
id: b.id,
type: b.geometry.type,
long: b.geometry.coordinates[0] ,
lat: b.geometry.coordinates[1] ,
description: b.properties.description,
iconCaption: b.properties.iconCaption?b.properties.iconCaption:"none",
markercolor: b.properties["marker-color"]
};
}
)
Example Fetch
http://127.0.0.1:3000/map
http://127.0.0.1:3000/api/id/24867
var url = new URL("http://127.0.0.1:3000/api/id/24867"),
params = {lat:35.696233, long:139.570431};
Object.keys(params).forEach(key => url.searchParams.append(key, params[key]))
fetch(url)
.then(response => response.json())
.then(data => console.log(data))