npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

json2proto

v1.0.0

Published

Json2proto is a command line tool for converting some json files to protobuf's proto file.

Downloads

9

Readme

Json2proto

Json2proto is a command line tool for converting some json files to protobuf's proto file.
json2proto���԰Ѷ����洢json�������ļ���Ϊ[ProtoBuf](https://developers.google.com/protocol-buffers/)��proto�ļ���

Solution

����������һ��json������
	p0 : {
		"x" : 0,
		"y" : 1
	}

������[ProtoBuf](https://developers.google.com/protocol-buffers/)����ʾ�������Ϳ����������ģ�
	message Position1 {
	  optional int8 x = 1;
	  optional int8 y = 2;
	}
��Ȼ������������Ҳ���ܴ洢����������, ֻ�Ƕ��˸������ֶ�, �ַ����ͷ�Χ����һЩ���ѡ�
	message Position2 {
	  optional int32 x = 1;
	  optional int32 y = 2;
	  optional int32 z = 3;
	}

����ͬʱҪ�洢p0��������p1����
	p1 : {
		x : 0,
		y : 1,
		z : 2.5
	}
��ô��С(�����ֶΣ� ��С��Χ������)�Ŀ���ͬʱ��������������������Ӧ���������ģ�
	message Position3 {
		optional uint8 x = 1;
		optional uint8 y = 2;
		optional float z = 3;
	}


json2protoͨ�������е������ֶ�_title�� ��ȷ����Щ��������ͬһ�����ͣ� ��������С����������Щ���������͡�
����û��_title�ֶεĶ����� json2proto����ͨ��-a�������Զ����շ���·������_title��

Install

  1. Install node.js

  2. Install with npm

    npm install -g json2proto

Usage

	Usage: json2proto [options] file
	Options:
	  -h, --help                   Display this information.
	  -v, --version                Print the compiler version.
	  -o, --output                 Set the output file name.
	  -a, --auto                   Automatically generate a title for unnamed object.
	  -p, --prefix                 Set the class name prefix, default prefix is json2proto
	  -n, --namespace              Set the namespace, default namespace is json2proto
	  -t, --title_tag              Specify the title_tag for searching class name, default title is "_title".

Example

motion.json:
	{
			"rows": [
			{
					"motion_id": 11001,
							"name": "���˼粿�³�",
							"privileges": [
									"owner",
							"admin",
							"user",
							"guest"
									],
							"type": "����",
							"category": "��"
			},
			{
					"motion_id": 11002,
					"name": "ֱ���粿�³�",
					"privileges": [
							"owner",
					"admin",
					"user",
					"guest"
							],
					"type": "����",
					"category": "��"
			}
			]
	}

command line:
	json2pb -omotion.proto -a motion.json

motion.proto:    
	syntax = "proto3";
	package json2proto ;

	message json2proto_motion {
		repeated json2proto_motion_rows rows = 1;
	}

	message json2proto_motion_rows {
				 int32 motion_id = 1;
				 string name = 2;
		repeated string privileges = 3;
				 string type = 4;
				 string category = 5;
	}


����ԭʼjson�ļ��в�������_title�ֶΣ� ������-a�������Զ�������
motion.jot
{
		"rows": [
			{
				"motion_id": 11001,
				"name": "���˼粿�³�",
				"privileges": [
					"owner",
					"admin",
					"user",
					"guest"
				],
				"type": "����",
				"category": "��",
				"_title": "json2proto_motion_rows"
			},
			{
				"motion_id": 11002,
				"name": "ֱ���粿�³�",
				"privileges": [
					"owner",
					"admin",
					"user",
					"guest"
				],
				"type": "����",
				"category": "��",
				"_title": "json2proto_motion_rows"
			}
		],
		"_title": "json2proto_motion"
	}

Author

@randyliu

Licence

See the MIT License