0

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
....
1
  • 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. Commented Dec 12, 2010 at 12:22

2 Answers 2

1

JSON Query Links:

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

0

You can add SculeJS to the above list. It does what you're looking for using a MongoDB style query interface, and it's written in JavaScript.

1
  • SculeJS seems to have nice features. Thanks Commented Feb 25, 2013 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.