SQL style JOIN on JSON data

后端 未结 3 1284
Happy的楠姐
Happy的楠姐 2020-12-16 13:51

Is there any way efficiently to join JSON data? Suppose we have two JSON datasets:

{\"COLORS\":[[1,red],[2,yellow],[3,orange]]}

{\"FRUITS\":[[1,apple],[2,ba         


        
3条回答
  •  误落风尘
    2020-12-16 14:41

    Alasql JavaScript SQL library does exactly what you need in one line:

     
     
    

    You can play with this example in jsFiddle.

    This is a SQL expression, where:

    • SELECT - select operator
    • MATRIX - modifier, whci converts resultset from array of objects to array of arrays
    • COLORS.[0] - first column of COLORS array, etc.
    • FRUITS.1 AS 2 - the second column of array FRUITS will be stored as third column in resulting recordset
    • FROM ? AS COLORS - data array from parameters named COLORS in SQL statement
    • JOIN ? ON ... - join
    • [data.COLORS, data.FRUITS] - parameters with data arrays

提交回复
热议问题