Javascript to convert all tables on a sheet to JSON


#1

How do I do that?

The more usual way to do things is to make a sheet object (or whatever it is) available. Then, that can be queried for tables, and those tables can be queried for rows. Metadata on all is available, such as the names of the sheet/table/whatever, the datatypes of each column/whatever, etc.


#2

Hi,

Do you mean a JSON containing all metadata for the “sheet design” (no data)?
If so, we do have an internal API for this, but right now it’s not opened for the public. Could you let me know your use case so we can see if this API is something we should make public?

Thanks,
Jeff


#3

The goal is to post all the data for a table plus two additional user-provided values to an external service that I’ll write. Wherever one can put an action button, I want to be able to add an action button that when clicked will get the data from the current page plus those two additional values.

The data I want to send would look like this:

{
  'user_value_1': 'some value',
  'user_value_2': 'some other value',
  'rows': [
    {
      'name': 'something',
      'address': '123 Main',
      'city': 'sometown'
    },
    {
      'name': 'something',
      'address': '123 Main',
      'city': 'sometown'
    },
    {
      'name': 'something',
      'address': '123 Main',
      'city': 'sometown'
    },
  ]
}

#4

Hi

Do you mean using the API? https://www.ragic.com/intl/en/doc-api/7/Finding-API-endpoints

Or do you want to press a button and send the JSON over to an Service?, When you know how to use javascript you could fetch data from the sheet with the javascript API and convert it to json.

Ragic JS manual: https://www.ragic.com/intl/en/doc/15/Javascript-workflow-engine

Example by string:

Example by Js object:

To get the table structure of your database use this api call https://www.ragic.com/{{YOURURI}}/?v=3&api
And https://www.ragic.com/{{YOURURI}}/{{YOURSHEETS}}?v=3&api

Does this answer your question?


#5

I know how to create the JSON I want. I’m asking how to get that from the API. Without having to hardcode table/row names, I want to do something like this in Javascript:

var tables = Ragic.getTables();
var data = tables[ 0 ].getData();
// convert data to JSON and send to an external service I’ll write.


#6

Without opening up the internal API for sheet metadata, you can probably do an API call without naming=EID parameter and get the values for each record under their field name. This way you still don’t really need to hardcode the field names, you can just iterate through the data to find the list of field names. It’s just that you don’t have the exact field types.