# Smarter JSON from SQL

**URL:** <https://community.dreamfactory.com/t/smarter-json-from-sql/1910>\
**Category:** REST API\
**Created:** [December 10, 2015, 4:44pm UTC](https://community.dreamfactory.com/t/smarter-json-from-sql/1910 "2015-12-10T16:44:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kieranrushby](https://avatars.discourse-cdn.com/v4/letter/k/f9ae1b/32.png) [@kieranrushby](https://community.dreamfactory.com/u/kieranrushby)\
**Post date:** [December 10, 2015, 4:44pm UTC](https://community.dreamfactory.com/t/smarter-json-from-sql/1910/1 "2015-12-10T16:44:55Z")

</div>

Hi,

I’m wondering… is there a way you can write your SQL Stored Procedures to return a smarter or more tidy JSON object rather than just a mass of columns? For example I have one SP which returns quote and customer information but I would love it if it could come back with the quote info in one property and the customer in another without having to call two SPs and setting the data manually. e.g. …

{  
quote: column column column,  
customer: column column column  
}

May seem petty but just wondering…

Cheers

---

<div class="post-metadata">

**Author:** ![kimpatro](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/kimpatro/32/467_2.png) [@kimpatro](https://community.dreamfactory.com/u/kimpatro)\
**Post date:** [December 10, 2015, 5:57pm UTC](https://community.dreamfactory.com/t/smarter-json-from-sql/1910/2 "2015-12-10T17:57:52Z")

</div>

Yes, you just need to create a procedure in your DB, then you call via GET this way:

`/your-db-service/_proc/{procedure_name}`

---

<div class="post-metadata">

**Author:** ![kieranrushby](https://avatars.discourse-cdn.com/v4/letter/k/f9ae1b/32.png) [@kieranrushby](https://community.dreamfactory.com/u/kieranrushby)\
**Post date:** [December 11, 2015, 9:12am UTC](https://community.dreamfactory.com/t/smarter-json-from-sql/1910/3 "2015-12-11T09:12:57Z")

</div>

This is yes calling a stored procedure, but my question is more around is there a way to write your procedure that would return the data in separate properties without having to call multiple procedures.

So rather than this coming back…

{  
quotecolumn1, quotecolumn2, quotecolumn3, customercolumn1, customercolumn2, customercolumn3  
}

if could come back  
{  
quote: quotecolumn1, quotecolumn2, quotecolumn3,  
customer: customercolumn1, customercolumn2, customercolumn3  
}

Cheers

---

<div class="post-metadata">

**Author:** ![kimpatro](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/kimpatro/32/467_2.png) [@kimpatro](https://community.dreamfactory.com/u/kimpatro)\
**Post date:** [December 11, 2015, 10:59am UTC](https://community.dreamfactory.com/t/smarter-json-from-sql/1910/4 "2015-12-11T10:59:50Z")

</div>

Ah sorry,

Ok, one way is creating a Custom Script that call those two SP and return a JSON with those two SP grouped as result.

Ex code:

```
quotes = platform.api.get('db-service/_proc/sp_get_quotes').result();
customers = platform.api.get('db-service/_proc/sp_get_customers').result();

var returnData = [
  {
    quotes: quotes,
    customers: customers
  };
]

return returnData;

```

and your app consumes the custom script.

With SP it’s not possible cause DF just consume the SP and return the result, there isn’t exists a post or pre process to the \_proc event.
