一种轻松、用户友好的jsonlike数据格式。

jsn的Python项目详细描述


jsn公司

Build StatusBuild StatuscodecovPyPI VersionLicense: MIT

jsn是一种用户友好的数据格式,可以很容易地被人阅读和编辑。在

它增加了继承、变量、包含和语法改进等强大功能,使jsn文件比json文件更紧凑和可重用,是多平台构建配置、打包和内容构建管道的理想解决方案。在

jsn可以作为字典直接在python中使用,也可以将其转换为json,以便与其他支持json的语言、工具和库一起使用。在

如果您正在任何项目中使用手工编辑的json,jsn将很容易地集成到您现有的工作流中,并提高效率和可靠性。在

特点

  • 包括/文件导入。在
  • 继承(层次结构和多重)。在
  • 环境样式范围变量。在
  • 无引号的钥匙。在
  • 无引号的字符串。在
  • 单引号。在
  • 单行和多行注释。在
  • 多行字符串/换行符。在
  • 十六进制,二进制,位移位,整型和浮点型改进。在

命令行接口

您可以使用命令行将jsn转换为json,克隆这个存储库并将jsn添加到您的路径中。在

jsn -i example.jsn -o example.json -I import_dir
^{pr2}$

Python API

通过pip安装:

python3 -m pip install jsn

或者复制jsn.py公司在你需要的地方。在

jsn可以像json一样用作python字典。在

importjsnjson_dict=jsn.loads(open("jsn_file.jsn","r").read())

示例.jsn

importimport.jsnimporttest.jsn{// sytax highlights quite nicely in most editors with c or c++ syntax      // allow comments/*    multi-    line     comments    *///        tabs and any whitespace allowed// compatible with json"json":{"bool":true,"int":1,"float":1.0,"string":"yes","array":[1,2,3]},// compatible with json5json5:{unquoted:'andyoucanquotemeonthat',single_quotes:'Icanuse"double quotes"here',hexadecimal:0xdecaf,line_breaks:"Look, Mom! No \\\n's!",leading_decimal_point:.8675309,and_trailing:8675309.,positive_sign:+1,trailing_comma:'inobjects',and_in:['arrays',],},// jsn featuresjsn:{// ditch the quotes and commas!unquoted_string:without_whitespace// cannot contain whitespace or special chars (see str_test)unquoted:[strings,in,arrays]binary_literal:0b10011bit_shifts:1<<16|1<<8// mixed newline and commasobject_members_separated_by_newline:{no_commas:yeswith_new_lines:"if you like"but:"you can",still:"use them here"}arrays_elements_separated_by_newline:["no need for commas""if you use newlines""still","separate","using commas","on the same line"]// you can define variables to be re-usedjsn_vars:{data:"path/to/data"var_str:"hello"var_int:10}// evaluate variables with ${} inside quotes..variable_data_path:"${data}/subdir"variable_int:"${var_int}"array_of_vars:["${data}","${var_str}"]// subobjects can be merged and inherited recursively see ** inheritence(jsn)base:"foo"sub_object:{one:"1"two:"2"nested_var:"${var_int}"// variable comes from outer scope.}// use <windows, mac, linux> in angled brackets to conditionally include or exclude keys// the platform specific keys will be merged into the base key if one existsplatform:{base:"exists"}// useful for selecting platform specific paths and executablesplatform<windows>:{exe:"path/windows/program.exe"}platform<mac>:{exe:"path/mac/program"}},//** inheritence(jsn):// add object name to inherit inside parenthesis{// inheritance adds keys from 'jsn' object// ..// duplicated keys are overridden by the derived objectbase:"bar",// inheritance on sub-objects continues recursivelysub_object:{three:"3"//..}},// multiple and hierarchical inheritanceobjb:{b:"b"},multiple_inheritence(inheritence,objb):{// vars can also be shadowed / overriden..jsn_vars:{data:"another/path/to/data",var_int:22},c:"c"},xxx:{// some test casesempty_object:{},empty_array:[],array_of_objects:[{object:1,other:"value"},{object:2,other:"value"}],array_with_string_commas:["test,2","test,3"],nested_objects:{yes:true,and:{deeper:nesting}},multi_type_arrays:[1,[2,3]],array_of_arrays:[[hello,world],[goodbye,world]],array_of_values:[+255,0b11111111,0xff,1<<1,1<<2|1,1<<2|1,.255],jsn_vars:{va:"path/to/data",vb:"hello",},array_of_array_vars:[["${va}","${vb}"],["${vb}","non var"]],multiple_vars:"${va}/${vb}.bin",q1:"small 'quotes' inside",q2:'double"quotes"inside',q3:"double escaped \"quotes\" inside"},//**str_test:":[{}]'+.,0b0x"// this tests ignoring special chars inside quotes}

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Spring启动启用HTTPS   actionscript 3 java中的这个[“var”+“name”]   java只匹配给定集合中一个字符的一个匹配项   java Hibernate:防止角色表中出现多个相同的条目   javajersey+Spring注入servlet请求   java HtmlEditor javafx失去焦点   java Apache Wicket AjaxRequestTarget ListView组件未刷新或更新   mysql java。无法将lang.String转换为java。sql。时间戳   java将巨大的整数文件(在一行中)拆分为具有内存限制的已排序块   安卓如何完全关闭proguard?   安装Eclipse和Android SDK后的java“无AVD可用”消息   java动态显示图像视图   java在Spring中还有哪些WebsocketClient实现?   java Glassfish需要很长时间才能重新启动   使用Java简单串行连接器将pc与arduino连接   java如何在camel文件组件配置中结合readLockCheckInterval和maxMessagesPerPoll?   单击Android时的java预览图像   java如何将字节数组转换为ByteArrayOutputStream