Opened 8 years ago

Closed 8 years ago

#1323 closed defect (fixed)

json format encode

Reported by: Dimitar Misev Owned by:
Priority: major Milestone: 9.3
Component: conversion Version: development
Keywords: Cc: Peter Baumann, Alex Dumitru, Vlad Merticariu
Complexity: Medium

Description

3D csv encode example:

RASQL="rasql --user rasadmin --passwd rasadmin"
$RASQL -q "create collection test_csv UShortSet3"
$RASQL -q "insert into test_csv values marray i in [0:1,0:2,0:3] values 1us"
$RASQL -q "select csv(c) from test_csv as c" --out string --quiet
{
  {1,1,1,1},
  {1,1,1,1},
  {1,1,1,1}
},
{
  {1,1,1,1},
  {1,1,1,1},
  {1,1,1,1}
}

A json alternative encoding should be straightforward with just substituting '{' and '}' with '[' and ']', and adding an outer brackets pair (unless I'm wrong about the array syntax in json):

[
 [
   [1,1,1,1],
   [1,1,1,1],
   [1,1,1,1]
 ],
 [
   [1,1,1,1],
   [1,1,1,1],
   [1,1,1,1]
 ]
]

Change History (1)

comment:1 by Dimitar Misev, 8 years ago

Resolution: fixed
Status: newclosed

Example use

encode

RASQL="rasql --user rasadmin --passwd rasadmin"
$RASQL -q "create collection test_csv UShortSet3"
$RASQL -q "insert into test_csv values marray i in [0:1,0:2,0:3] values 1us"
$RASQL -q "select encode(c, "json") from test_csv as c" --out string --quiet
[
 [
   [1,1,1,1],
   [1,1,1,1],
   [1,1,1,1]
 ],
 [
   [1,1,1,1],
   [1,1,1,1],
   [1,1,1,1]
 ]
]

A mimetype that also works is "application/json":

$RASQL -q "select encode(c, "application/json") from test_csv as c" --out string --quiet

decode

Works exactly the same as CSV decode with same parameters, just the format is "json" rather than "csv", e.g:

insert into coll values decode($1, "json", "domain=[0:2,1:2,4:6];basetype=float")
Note: See TracTickets for help on using tickets.