2017 © Pedro Peláez
 

library json-to-go

PHP Implementation of mholt/json-to-go

image

dcarbone/json-to-go

PHP Implementation of mholt/json-to-go

  • Thursday, August 3, 2017
  • by dcarbone
  • Repository
  • 1 Watchers
  • 1 Stars
  • 147 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 45 Versions
  • 0 % Grown

The README.md

json-to-go

PHP Implementation of mholt/json-to-go, (*1)

Composer

{
    "require": {
        "dcarbone/json-to-go": "@stable"
    }
}

Why Do This in PHP?

Because it fits better into my personal workflow., (*2)

Also because why not., (*3)

Basic Usage

Once included in your project, the easiest way to use it is probably using the static initializers:, (*4)

$jsonToGO = \DCarbone\JSONToGO::parse('RootTypeName', $myjson);

This will return to you an instance of a concrete implementation of AbstractType with your input parsed. If there was an issue during parsing, an exception will be thrown., (*5)

For a complete list of possible types, see here, (*6)

This class implements __toString(), and the return value is the parsed GO object., (*7)

General Rules

  • If a property name in an object is entirely comprised of numbers, it will be prefixed with Num
  • If a property name in an object begins with a non-alphanumeric value, it will be prefixed with X
  • If a property name in an object has a numerical first character, that character will be converted to a string following the map seen here. (e.g.: 80211X becomes Eight_0211X) You may optionally define your own map when initializing the Configuration class.
  • If a type is not possible (is a NULL in the example json...), or if there is a value type conflict between keys within a map, the type will be defined as interface{}
  • The names for things will always be Exported
  • It is always a good idea to run the results through go fmt

Custom Configuration

There are a few possible options when parsing JSON, definable in the Configuration class:, (*8)

  • forceOmitEmpty - Will always place the json:,omitempty markup at the end of struct properties
  • forceIntToFloat - Will convert all int types to float.
  • useSimpleInt - Will, if using ints, use the simple int type rather than attempting to determine int32 vs int64
  • forceScalarToPointer - Will turn all simple types (string, int, float, bool) into pointers
  • emptyStructToInterface - Will convert an object without properties into an interface{}
  • breakOutInlineStructs - Will create bespoke type definitions for nested objects
  • sanitizeInput - Will override the values present in the example json (see here)
  • initialNumberMap- Array to use for converting number characters to alpha characters at the beginning of struct
  • callbacks - Instance of Callbacks or array of ['callback' => callable] where callback == name of parameter on Callbacks and callable == any valid php callable that accepts the parameters present in the function named the same as the property.

Map and RawMessage types

By default, the MapType and RawMessageType are never used. To take advantage of these types, you must implement your own goType that returns either map or raw respectively., (*9)

Examples:

Taking this example JSON payload (source):, (*10)

{"web-app": {
  "servlet": [   
    {
      "servlet-name": "cofaxCDS",
      "servlet-class": "org.cofax.cds.CDSServlet",
      "init-param": {
        "configGlossary:installationAt": "Philadelphia, PA",
        "configGlossary:adminEmail": "ksm@pobox.com",
        "configGlossary:poweredBy": "Cofax",
        "configGlossary:poweredByIcon": "/images/cofax.gif",
        "configGlossary:staticPath": "/content/static",
        "templateProcessorClass": "org.cofax.WysiwygTemplate",
        "templateLoaderClass": "org.cofax.FilesTemplateLoader",
        "templatePath": "templates",
        "templateOverridePath": "",
        "defaultListTemplate": "listTemplate.htm",
        "defaultFileTemplate": "articleTemplate.htm",
        "useJSP": false,
        "jspListTemplate": "listTemplate.jsp",
        "jspFileTemplate": "articleTemplate.jsp",
        "cachePackageTagsTrack": 200,
        "cachePackageTagsStore": 200,
        "cachePackageTagsRefresh": 60,
        "cacheTemplatesTrack": 100,
        "cacheTemplatesStore": 50,
        "cacheTemplatesRefresh": 15,
        "cachePagesTrack": 200,
        "cachePagesStore": 100,
        "cachePagesRefresh": 10,
        "cachePagesDirtyRead": 10,
        "searchEngineListTemplate": "forSearchEnginesList.htm",
        "searchEngineFileTemplate": "forSearchEngines.htm",
        "searchEngineRobotsDb": "WEB-INF/robots.db",
        "useDataStore": true,
        "dataStoreClass": "org.cofax.SqlDataStore",
        "redirectionClass": "org.cofax.SqlRedirection",
        "dataStoreName": "cofax",
        "dataStoreDriver": "com.microsoft.jdbc.sqlserver.SQLServerDriver",
        "dataStoreUrl": "jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon",
        "dataStoreUser": "sa",
        "dataStorePassword": "dataStoreTestQuery",
        "dataStoreTestQuery": "SET NOCOUNT ON;select test='test';",
        "dataStoreLogFile": "/usr/local/tomcat/logs/datastore.log",
        "dataStoreInitConns": 10,
        "dataStoreMaxConns": 100,
        "dataStoreConnUsageLimit": 100,
        "dataStoreLogLevel": "debug",
        "maxUrlLength": 500}},
    {
      "servlet-name": "cofaxEmail",
      "servlet-class": "org.cofax.cds.EmailServlet",
      "init-param": {
      "mailHost": "mail1",
      "mailHostOverride": "mail2"}},
    {
      "servlet-name": "cofaxAdmin",
      "servlet-class": "org.cofax.cds.AdminServlet"},

    {
      "servlet-name": "fileServlet",
      "servlet-class": "org.cofax.cds.FileServlet"},
    {
      "servlet-name": "cofaxTools",
      "servlet-class": "org.cofax.cms.CofaxToolsServlet",
      "init-param": {
        "templatePath": "toolstemplates/",
        "log": 1,
        "logLocation": "/usr/local/tomcat/logs/CofaxTools.log",
        "logMaxSize": "",
        "dataLog": 1,
        "dataLogLocation": "/usr/local/tomcat/logs/dataLog.log",
        "dataLogMaxSize": "",
        "removePageCache": "/content/admin/remove?cache=pages&id=",
        "removeTemplateCache": "/content/admin/remove?cache=templates&id=",
        "fileTransferFolder": "/usr/local/tomcat/webapps/content/fileTransferFolder",
        "lookInContext": 1,
        "adminGroupID": 4,
        "betaServer": true}}],
  "servlet-mapping": {
    "cofaxCDS": "/",
    "cofaxEmail": "/cofaxutil/aemail/*",
    "cofaxAdmin": "/admin/*",
    "fileServlet": "/static/*",
    "cofaxTools": "/tools/*"},

  "taglib": {
    "taglib-uri": "cofax.tld",
    "taglib-location": "/WEB-INF/tlds/cofax.tld"}}}

And executing the following:, (*11)

    $go = \DCarbone\JSONToGO::parse('RootTypeName', $json);

    file_put_contents(__DIR__.'/example.go', (string)$go);

Will result in (pre go fmt):, (*12)

type RootTypeName struct {
    WebApp struct {
            Servlet []struct {
                    ServletName string `json:"servlet-name"`
                    ServletClass string `json:"servlet-class"`
                    InitParam struct {
                            ConfigGlossaryInstallationAt string `json:"configGlossary:installationAt"`
                            ConfigGlossaryAdminEmail string `json:"configGlossary:adminEmail"`
                            ConfigGlossaryPoweredBy string `json:"configGlossary:poweredBy"`
                            ConfigGlossaryPoweredByIcon string `json:"configGlossary:poweredByIcon"`
                            ConfigGlossaryStaticPath string `json:"configGlossary:staticPath"`
                            TemplateProcessorClass string `json:"templateProcessorClass"`
                            TemplateLoaderClass string `json:"templateLoaderClass"`
                            TemplatePath string `json:"templatePath"`
                            TemplateOverridePath string `json:"templateOverridePath"`
                            DefaultListTemplate string `json:"defaultListTemplate"`
                            DefaultFileTemplate string `json:"defaultFileTemplate"`
                            UseJSP bool `json:"useJSP"`
                            JspListTemplate string `json:"jspListTemplate"`
                            JspFileTemplate string `json:"jspFileTemplate"`
                            CachePackageTagsTrack int `json:"cachePackageTagsTrack"`
                            CachePackageTagsStore int `json:"cachePackageTagsStore"`
                            CachePackageTagsRefresh int `json:"cachePackageTagsRefresh"`
                            CacheTemplatesTrack int `json:"cacheTemplatesTrack"`
                            CacheTemplatesStore int `json:"cacheTemplatesStore"`
                            CacheTemplatesRefresh int `json:"cacheTemplatesRefresh"`
                            CachePagesTrack int `json:"cachePagesTrack"`
                            CachePagesStore int `json:"cachePagesStore"`
                            CachePagesRefresh int `json:"cachePagesRefresh"`
                            CachePagesDirtyRead int `json:"cachePagesDirtyRead"`
                            SearchEngineListTemplate string `json:"searchEngineListTemplate"`
                            SearchEngineFileTemplate string `json:"searchEngineFileTemplate"`
                            SearchEngineRobotsDb string `json:"searchEngineRobotsDb"`
                            UseDataStore bool `json:"useDataStore"`
                            DataStoreClass string `json:"dataStoreClass"`
                            RedirectionClass string `json:"redirectionClass"`
                            DataStoreName string `json:"dataStoreName"`
                            DataStoreDriver string `json:"dataStoreDriver"`
                            DataStoreURL string `json:"dataStoreUrl"`
                            DataStoreUser string `json:"dataStoreUser"`
                            DataStorePassword string `json:"dataStorePassword"`
                            DataStoreTestQuery string `json:"dataStoreTestQuery"`
                            DataStoreLogFile string `json:"dataStoreLogFile"`
                            DataStoreInitConns int `json:"dataStoreInitConns"`
                            DataStoreMaxConns int `json:"dataStoreMaxConns"`
                            DataStoreConnUsageLimit int `json:"dataStoreConnUsageLimit"`
                            DataStoreLogLevel string `json:"dataStoreLogLevel"`
                            MaxURLLength int `json:"maxUrlLength"`
                        } `json:"init-param,omitempty"`
                } `json:"servlet"`
            ServletMapping struct {
                    CofaxCDS string `json:"cofaxCDS"`
                    CofaxEmail string `json:"cofaxEmail"`
                    CofaxAdmin string `json:"cofaxAdmin"`
                    FileServlet string `json:"fileServlet"`
                    CofaxTools string `json:"cofaxTools"`
                } `json:"servlet-mapping"`
            Taglib struct {
                    TaglibURI string `json:"taglib-uri"`
                    TaglibLocation string `json:"taglib-location"`
                } `json:"taglib"`
        } `json:"web-app"`
}

The Versions

03/08 2017

dev-master

9999999-dev

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

 

by Daniel Carbone

json go golang json to go

03/08 2017

0.8.0

0.8.0.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

 

by Daniel Carbone

json go golang json to go

03/08 2017

0.8.x-dev

0.8.9999999.9999999-dev

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

 

by Daniel Carbone

json go golang json to go

24/02 2017

0.7.3

0.7.3.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

 

by Daniel Carbone

json go golang json to go

14/02 2017

0.7.2

0.7.2.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

 

by Daniel Carbone

json go golang json to go

10/02 2017

0.7.1

0.7.1.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

 

by Daniel Carbone

json go golang json to go

09/02 2017

0.7.0

0.7.0.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

 

by Daniel Carbone

json go golang json to go

08/02 2017

0.6.4

0.6.4.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

07/02 2017

0.6.3

0.6.3.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

07/02 2017

0.6.2

0.6.2.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

06/02 2017

0.6.1

0.6.1.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

03/02 2017

0.6.0

0.6.0.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

31/01 2017

0.5.4

0.5.4.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

30/01 2017

0.5.3

0.5.3.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

15/01 2017

0.5.2

0.5.2.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

15/01 2017

0.5.1

0.5.1.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

15/01 2017

0.5.0

0.5.0.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

15/12 2016

0.4.0

0.4.0.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

14/12 2016

0.3.13

0.3.13.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

14/12 2016

0.3.12

0.3.12.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

14/12 2016

0.3.11

0.3.11.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

14/12 2016

0.3.10

0.3.10.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

14/12 2016

0.3.9

0.3.9.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

14/12 2016

0.3.8

0.3.8.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

10/12 2016

0.3.7

0.3.7.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

09/12 2016

0.3.6

0.3.6.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

09/12 2016

0.3.5

0.3.5.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

08/12 2016

0.3.4

0.3.4.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

07/12 2016

0.3.3

0.3.3.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

07/12 2016

0.3.2

0.3.2.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

07/12 2016

0.3.1

0.3.1.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

07/12 2016

0.3.0

0.3.0.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

02/12 2016

0.2.7

0.2.7.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

02/12 2016

0.2.6

0.2.6.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

28/11 2016

0.2.5

0.2.5.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

23/11 2016

0.2.4

0.2.4.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

23/11 2016

0.2.3

0.2.3.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

09/11 2016

0.2.2

0.2.2.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Daniel Carbone

json go golang json to go

08/11 2016

0.2.1

0.2.1.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

by Daniel Carbone
by Matt Holt

json go golang json to go

08/11 2016

0.2.0

0.2.0.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

by Daniel Carbone
by Matt Holt

json go golang json to go

08/11 2016

0.1.4

0.1.4.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

by Daniel Carbone
by Matt Holt

json go golang json to go

04/11 2016

0.1.3

0.1.3.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

by Daniel Carbone
by Matt Holt

json go golang json to go

01/11 2016

0.1.2

0.1.2.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

by Daniel Carbone
by Matt Holt

json go golang json to go

01/11 2016

0.1.1

0.1.1.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

by Daniel Carbone
by Matt Holt

json go golang json to go

27/10 2016

0.1.0

0.1.0.0

PHP Implementation of mholt/json-to-go

  Sources   Download

MIT

by Daniel Carbone
by Matt Holt

json go golang json to go