Skip to content

Custom data formats

Vladimir Jimenez edited this page Jun 5, 2015 · 1 revision

PhpSoda provides a Converter class that allows you to write your own conversions of data formats in order to upsert() or replace() the data.

The CsvConverter class, which is provided as an official method of supporting CSV, extends the Converter class and provides a toJson() method that converts CSV to JSON.

You may support your own data format by extending the Converter class and defining the toJson() function in order for PhpSoda to be able to submit it to Socrata as JSON since PhpSoda only supports sending data as JSON.

Example

You may look at the CsvConverter class as a complete example.

<?php

namespace my\namespace\SocrataConverters;

class MyDataFormatConverter extends Converter
{
    public function toJson ()
    {
        // Access the data given to this Converter by calling $this->data

        // ...code to convert to JSON
    }
}