Return plain json from JIG

64 views
Skip to first unread message

Anatol

unread,
Apr 11, 2017, 3:11:12 PM4/11/17
to Fat-Free Framework
Hi,

for a little website I´m dealing with geojson. Normally I use postgis for heavy stuff like this but as F3 has JIG with JSON Format I thought it could work to
use it and benefit from mapper / cursor sweetness.

Unfortunately it feels so close yet so far ... Here are my needs.

My JIG DB looks like this:

{ "58eceeadb67fd3.98642197": {
        "type": "Feature",
        "geometry": {
            "type": "Point",
            "coordinates": [125.6,10.1]
        },
        "properties": {
            "id": "1",
            "name": "Dinagat Islands",
            "desc": "Coffee is good"
        }
    },
    "58eceee4530111.78843208": {
        "type": "yeas",
        "geometry": {
            "type": "Point",
            "coordinates": [0,0]
        },
        "properties": {
            "id": "2",
            "name": "Null Island",
            "desc": "New desc"
        }
    }
}



1.) 

How could I get raw JSON data of all entry means everything under each hash key (f.e. 58eceee4530111.78843208)
In the end I would need a JSON structure like.

PSEUDO CODE: $results = $mapper->fullRawJson( '' )

{
 
   
"type":"FeatureCollection",
   
"features":[  
         
{  
         
"type": "Feature",
         
"geometry": {
           
"type": "Point",
           
"coordinates": [125.6, 10.1]
       
},
       
"properties": {
           
"id":"1",
           
"name": "Dinagat Islands",            
           
"desc":"Coffee is good"
       
}
   
     
},
     
{  
       
"type": "Feature",
       
"geometry": {
           
"type": "Point",
           
"coordinates": [0,0]
       
},
       
"properties": {
           
"id":"2",
           
"name": "Null Island",
           
"desc":"beer is better"
       
}
     
}
   
]
}

I´ve checked ->read() ->load() ->find() and to extend cursor / JIG Mapper but cannot see the forest because of trees.
(Maybe because I spare to decode as it´s already in JSON)

2)

Say I´m loading an object like 
$results = $mapper->load( array('@properties.id = ?',2) );

Same here I would need RAW JSON object returned looking like:

{  
       
"type": "Feature",
       
"geometry": {
           
"type": "Point",
           
"coordinates": [0,0]
       
},
       
"properties": {
           
"id":"2",
           
"name": "Null Island",
           
"desc":"beer is better"
       
}
     
}


As always, 
thanks for you ideas and help.

– anatol

ikkez

unread,
Apr 11, 2017, 5:08:13 PM4/11/17
to f3-fra...@googlegroups.com
You are joking, aren't you?

1.)

$results = $f3->read('yourdb.json');

or

$results = json_encode(array_map(array($mapper,'cast'),$mapper->find()))

2.)

$results = json_encode($mapper->load()->cast());

Anatol

unread,
Apr 11, 2017, 6:27:37 PM4/11/17
to Fat-Free Framework
Oh shit Ikkez,
shame on me. I was making thing to complicated.
I was at this pointed but then started somehow reinventing the wheel

¯\_(ツ)_/¯


thanks!

Summer White

unread,
Apr 18, 2017, 2:31:04 AM4/18/17
to Fat-Free Framework
I didn't know $f3->read did that. Thank you!
Reply all
Reply to author
Forward
0 new messages