I saw many questions about json in stackoverflow. Most of them are unanswered or the basic idea is relaying on already existing techiniques.

I want to build json db to use it in a easy way as a query usage. Like SELECT a WHERE a = $var;

Please your suggestions.
Thanks in advance.

    //sample jsondb
     {
      "name": "test",
      "columns": ["a", "b"],
      "rows":   [[1, 2],
                 [3, 4]]
      }


    $var = 3;
    //the aim is to use it easy as query usage
    SELECT a WHERE a = $var;

   //sample json object retrieved by PHP's json_encode() 
stdClass Object
    (
        [name] => test
        [columns] => Array
            (
                [0] => a
                [1] => b
            )

        [rows] => Array
            (
                [0] => Array
                    (
                        [0] => 1
                        [1] => 2
                    )

                [1] => Array
                    (
                        [0] => 3
                        [1] => 4
                    )

            )

    )

     //have the column a 
     $cols = array_flip($obj->columns);
     $col_a = $cols['a'];

     //filter to a=$var
     $rows_with_value_3 = array();
     foreach($obj->rows as $index => $rowvalues){

        foreach($rowvalues as $value){
            if($value[$col_a] == $var)
            $rows_with_value_3[$index] = $value[$col_a];
        }
     }

    //below the query string build functions
....
share|improve this question

60% accept rate
SQL is mainly aimed for simple table (row/column) structures, you need something more like XPATH for JSON, which if I recall correctly is already out in the wild somewhere. – BGerrissen Dec 12 '10 at 12:22
feedback

1 Answer

up vote 1 down vote accepted

JSON Query Links:

Check Databases using JSON as storage/transport format for JSON Databases.

share|improve this answer
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.