conversion from json to protobuf

924 views
Skip to first unread message

rifo...@gmail.com

unread,
Dec 2, 2014, 12:37:58 PM12/2/14
to pi...@googlegroups.com
Hello,

I want to use piqi for converting a json file to a protocol buffer file. I use the following command

    $  ./piqi convert -f json -t pib sample.json -o
         sample.json:1:1: default type for JSON object is unknown

The json file is downloaded from json.org

{
    "glossary": {
        "title": "example glossary",
        "GlossDiv": {
            "title": "S",
            "GlossList": {
                "GlossEntry": {
                    "ID": "SGML",
                    "SortAs": "SGML",
                    "GlossTerm": "Standard Generalized Markup Language",
                    "Acronym": "SGML",
                    "Abbrev": "ISO 8879:1986",
                    "GlossDef": {
                        "para": "A meta-markup language, used to create markup languages such as DocBook.",
                        "GlossSeeAlso": ["GML", "XML"]
                    },
                    "GlossSee": "markup"
                }
            }
        }
    }
}


I have also tried converting into a piq format but got the same error

    $  ./piqi convert sample.json
        sample.json:1:1: default type for JSON object is unknown


Can you please guide me in the right direction?

thank you
rifo

Anton Lavrik

unread,
Dec 3, 2014, 6:18:14 AM12/3/14
to pi...@googlegroups.com, rifo...@gmail.com
Hi,

You'll need a schema definition if you want to do something like that. Unlike JSON, Protocol Buffers can't be used without a schema.

Piqi works with two schema formats. One is protobuf native: https://developers.google.com/protocol-buffers/docs/proto The second one is the piqi schema language itself: http://piqi.org/doc/piqi/  You can use "piqi to-proto" and "piqi of-proto" convert one into another.

Once you come up with a schema describing your protocol buffers data, you can use "piqi convert" as follows:

piqi convert --type <type> -f json -t pb -o sample.pb sample.json

where <type> is <your .piqi module>/<your top-level typename>

Anton


--
You received this message because you are subscribed to the Google Groups "piqi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to piqi+uns...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

rifo...@gmail.com

unread,
Dec 3, 2014, 11:19:41 AM12/3/14
to pi...@googlegroups.com, rifo...@gmail.com
Hello Anton,

Thanks a lot for your answer. I'll follow your tips.

rifat
Reply all
Reply to author
Forward
0 new messages