将java properties转成json格式的工具:Props2Json
jopen
10年前
props2json是一个命令行实用程序/类库,用于将Java properties 转换成JSON格式。对配置生成和作为简单的properties 至 pojo映射非常好用。 支持有嵌套结构和数组。
Example
Sample Properties file
a=123 b=abc c=True d.e=True d.f=False negativeNum=-1 positiveFloat=0.189 negativeFloat=-0.189 e.list=1,2,3,4,5,6,7,8,9,10 f.list=-1,2.1,-3.14,0,0.0,true,false,TRUE,FALSE,David
Sample Json output
{ "b": "abc", "a": 123, "negativeFloat": -0.189, "negativeNum": -1, "d": { "f": false, "e": true }, "e": { "list": [ -1, 2.1, -3.14, 0, 0.0, true, false, true, false, "David" ] }, "c": true }编码使用:
import com.aahmedse.props2json.PropsToJsonUtil; import java.util.Properties; public class Sample { public static void main(String args[]){ Properties p = new Properties(); p.setProperty("a", "123"); p.setProperty("b", "abc"); p.setProperty("c", "True"); p.setProperty("d.e", "True"); p.setProperty("d.f", "False"); p.setProperty("negativeNum", "-1"); p.setProperty("negativeFloat", "-0.189"); p.setProperty("negativeFloat", "-0.189"); p.setProperty("e.list", "1,2,3,4,5,6,7,8,9,10"); p.setProperty("e.list", "-1,2.1,-3.14,0,0.0,true,false,TRUE,FALSE,David"); System.out.println(PropsToJsonUtil.convertToJson(p)); } }