SQL Anywhere 16.0.0.1915

We are developing a JSON payload to be passed via a web service to an IOS application. It is simple enough to use the FOR JSON AUTO clause and I have obtained a variety of JSON selects. But our iPad developers have asked for a combined payload that would concatenate several selects into a single long varchar.

How to accomplish that escapes me.

asked 14 Sep '16, 17:04

Bill%20Aumen's gravatar image

Bill Aumen
2.1k354775
accept rate: 16%

1

into a single long varchar.

As JSON uses UTF-8 encoding by default, you might prefer a long nvarchar.

(15 Sep '16, 03:51) Volker Barth

Thanks for the ideas, looks like I will just "string" the data together. (Glad JSON is rather simple in that regard.)

The basic SELECT... FOR JSON is so easy, I was hoping for one more silver bullet: - SELECT * FROM A FOR JSON INTO ls_jsona; - SELECT * FROM B FOR JSON INTO ls_jsonb; - SELECT ls_jsona || ls_jsonb; OR: - SELECT * FROM A FOR JSON UNION ALL SELECT * FROM B FOR JSON;

Guess I'll have to actually do some work :-).

Thanks, Bill

permanent link

answered 15 Sep '16, 10:36

Bill%20Aumen's gravatar image

Bill Aumen
2.1k354775
accept rate: 16%

If you have create for example two JSON Strings in two variables.

set json1 = '{"Name": "Bob"};
set json1 = '{"Name": "Mary"};

You can combine these two JSON Objects in an array.

select string('[', json1, ',', json2, ']';

So instead of having different web service calls for different select statements you concatenate them in one variable and return the combine result as payload.

HTH

permanent link

answered 15 Sep '16, 02:22

Thomas%20Duemesnil's gravatar image

Thomas Dueme...
2.7k293965
accept rate: 17%

1

Likewise you could create a JSON object instead of an array:

select string('{ "obj1" : ', json1, ', "obj2" : ', json2, '}';
(15 Sep '16, 03:47) Volker Barth
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×30
×1

question asked: 14 Sep '16, 17:04

question was seen: 2,539 times

last updated: 15 Sep '16, 10:36