Skip to content
Permalink
Browse files

Rename json functions to postgres names

  • Loading branch information
m-kuhn authored and nirvn committed Jan 18, 2019
1 parent 01e2b80 commit 008dfeed40ced538f112e4731c9114c4e7f75042
@@ -1,11 +1,11 @@
{
"name": "load_json",
"name": "from_json",
"type": "function",
"description": "Loads a JSON formatted string.",
"arguments": [
{"arg":"string", "description":"JSON string"}],
"examples": [
{"expression":"load_json('{\"qgis\":\"rocks\"}')", "returns":"{ \"qgis\" : \"rocks\" }"},
{"expression":"load_json('[1,2,3]')", "returns":"[1,2,3]"}
{"expression":"from_json('{\"qgis\":\"rocks\"}')", "returns":"{ \"qgis\" : \"rocks\" }"},
{"expression":"from_json('[1,2,3]')", "returns":"[1,2,3]"}
]
}
@@ -1,11 +1,11 @@
{
"name": "write_json",
"name": "to_json",
"type": "function",
"description": "Create a JSON formatted string from a map, array or other value.",
"arguments": [
{"arg":"value", "description":"The input value"}],
"examples": [
{ "expression":"write_json(map('qgis','rocks'))", "returns":"{\"qgis\":\"rocks\"}"},
{ "expression":"write_json(array(1,2,3))", "returns":"[1,2,3]"}
{ "expression":"to_json(map('qgis','rocks'))", "returns":"{\"qgis\":\"rocks\"}"},
{ "expression":"to_json(array(1,2,3))", "returns":"[1,2,3]"}
]
}
@@ -5300,9 +5300,9 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()

//functions for maps
<< new QgsStaticExpressionFunction( QStringLiteral( "json_to_map" ), 1, fcnLoadJson, QStringLiteral( "Maps" ) )
<< new QgsStaticExpressionFunction( QStringLiteral( "load_json" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "value" ) ), fcnLoadJson, QStringLiteral( "Maps" ) )
<< new QgsStaticExpressionFunction( QStringLiteral( "from_json" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "value" ) ), fcnLoadJson, QStringLiteral( "Maps" ) )
<< new QgsStaticExpressionFunction( QStringLiteral( "map_to_json" ), 1, fcnWriteJson, QStringLiteral( "Maps" ) )
<< new QgsStaticExpressionFunction( QStringLiteral( "write_json" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "json_string" ) ), fcnWriteJson, QStringLiteral( "Maps" ) )
<< new QgsStaticExpressionFunction( QStringLiteral( "to_json" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "json_string" ) ), fcnWriteJson, QStringLiteral( "Maps" ) )
<< new QgsStaticExpressionFunction( QStringLiteral( "hstore_to_map" ), 1, fcnHstoreToMap, QStringLiteral( "Maps" ) )
<< new QgsStaticExpressionFunction( QStringLiteral( "map_to_hstore" ), 1, fcnMapToHstore, QStringLiteral( "Maps" ) )
<< new QgsStaticExpressionFunction( QStringLiteral( "map" ), -1, fcnMap, QStringLiteral( "Maps" ) )
@@ -2962,11 +2962,11 @@ class TestQgsExpression: public QObject
QCOMPARE( QgsExpression( "map_concat(map('1', 'one', '2', 'overridden by next map'), map('2', 'two', '3', 'three'))" ).evaluate( &context ), QVariant( concatExpected ) );

QCOMPARE( QgsExpression( "json_to_map('{\"1\":\"one\",\"2\":\"two\",\"3\":\"three\"}')" ).evaluate( &context ), QVariant( concatExpected ) );
QCOMPARE( QgsExpression( "load_json('{\"1\":\"one\",\"2\":\"two\",\"3\":\"three\"}')" ).evaluate( &context ), QVariant( concatExpected ) );
QCOMPARE( QgsExpression( "load_json('[1,2,3]')" ).evaluate( &context ), QVariant( QVariantList() << 1 << 2 << 3 ) );
QCOMPARE( QgsExpression( "from_json('{\"1\":\"one\",\"2\":\"two\",\"3\":\"three\"}')" ).evaluate( &context ), QVariant( concatExpected ) );
QCOMPARE( QgsExpression( "from_json('[1,2,3]')" ).evaluate( &context ), QVariant( QVariantList() << 1 << 2 << 3 ) );
QCOMPARE( QgsExpression( "map_to_json(map('1','one','2','two','3','three'))" ).evaluate( &context ), QVariant( "{\"1\":\"one\",\"2\":\"two\",\"3\":\"three\"}" ) );
QCOMPARE( QgsExpression( "write_json(map('1','one','2','two','3','three'))" ).evaluate( &context ), QVariant( "{\"1\":\"one\",\"2\":\"two\",\"3\":\"three\"}" ) );
QCOMPARE( QgsExpression( "write_json(array(1,2,3))" ).evaluate( &context ), QVariant( QStringLiteral( "[1,2,3]" ) ) );
QCOMPARE( QgsExpression( "to_json(map('1','one','2','two','3','three'))" ).evaluate( &context ), QVariant( "{\"1\":\"one\",\"2\":\"two\",\"3\":\"three\"}" ) );
QCOMPARE( QgsExpression( "to_json(array(1,2,3))" ).evaluate( &context ), QVariant( QStringLiteral( "[1,2,3]" ) ) );

QCOMPARE( QgsExpression( "hstore_to_map('1=>one,2=>two,3=>three')" ).evaluate( &context ), QVariant( concatExpected ) );
QCOMPARE( QgsExpression( "map_to_hstore(map('1','one','2','two','3','three'))" ).evaluate( &context ), QVariant( "\"1\"=>\"one\",\"2\"=>\"two\",\"3\"=>\"three\"" ) );

0 comments on commit 008dfee

Please sign in to comment.
You can’t perform that action at this time.