├── .github └── workflows │ ├── build.yml │ └── test.yml ├── .gitignore ├── LICENSE ├── README.md ├── assets ├── charset2_result.hjson ├── charset2_result.json ├── charset2_test.hjson ├── charset_result.hjson ├── charset_result.json ├── charset_test.hjson ├── comments2_result.hjson ├── comments2_result.json ├── comments2_test.hjson ├── comments3_result.hjson ├── comments3_result.json ├── comments3_test.hjson ├── comments4_result.hjson ├── comments4_result.json ├── comments4_test.hjson ├── comments5_result.hjson ├── comments5_result.json ├── comments5_test.hjson ├── comments6_result.hjson ├── comments6_result.json ├── comments6_test.hjson ├── comments7_result.hjson ├── comments7_result.json ├── comments7_test.hjson ├── comments_result.hjson ├── comments_result.json ├── comments_test.hjson ├── empty_result.hjson ├── empty_result.json ├── empty_test.hjson ├── failCharset1_test.hjson ├── failJSON02_test.json ├── failJSON05_test.json ├── failJSON06_test.json ├── failJSON07_test.json ├── failJSON08_test.json ├── failJSON10_test.json ├── failJSON11_test.json ├── failJSON12_test.json ├── failJSON13_test.json ├── failJSON14_test.json ├── failJSON15_test.json ├── failJSON16_test.json ├── failJSON17_test.json ├── failJSON19_test.json ├── failJSON20_test.json ├── failJSON21_test.json ├── failJSON22_test.json ├── failJSON23_test.json ├── failJSON26_test.json ├── failJSON28_test.json ├── failJSON29_test.json ├── failJSON30_test.json ├── failJSON31_test.json ├── failJSON32_test.json ├── failJSON33_test.json ├── failJSON34_test.json ├── failKey1_test.hjson ├── failKey2_test.hjson ├── failKey3_test.hjson ├── failKey4_test.hjson ├── failKey5_test.hjson ├── failMLStr1_test.hjson ├── failObj1_test.hjson ├── failObj2_test.hjson ├── failObj3_test.hjson ├── failStr1a_test.hjson ├── failStr1b_test.hjson ├── failStr1c_test.hjson ├── failStr1d_test.hjson ├── failStr2a_test.hjson ├── failStr2b_test.hjson ├── failStr2c_test.hjson ├── failStr2d_test.hjson ├── failStr3a_test.hjson ├── failStr3b_test.hjson ├── failStr3c_test.hjson ├── failStr3d_test.hjson ├── failStr4a_test.hjson ├── failStr4b_test.hjson ├── failStr4c_test.hjson ├── failStr4d_test.hjson ├── failStr5a_test.hjson ├── failStr5b_test.hjson ├── failStr5c_test.hjson ├── failStr5d_test.hjson ├── failStr6a_test.hjson ├── failStr6b_test.hjson ├── failStr6c_test.hjson ├── failStr6d_test.hjson ├── failStr7a_test.hjson ├── failStr8a_test.hjson ├── kan_result.hjson ├── kan_result.json ├── kan_test.hjson ├── keys_result.hjson ├── keys_result.json ├── keys_test.hjson ├── mltabs_result.hjson ├── mltabs_result.json ├── mltabs_test.json ├── oa_result.hjson ├── oa_result.json ├── oa_test.hjson ├── pass1_result.hjson ├── pass1_result.json ├── pass1_test.json ├── pass2_result.hjson ├── pass2_result.json ├── pass2_test.json ├── pass3_result.hjson ├── pass3_result.json ├── pass3_test.json ├── pass4_result.hjson ├── pass4_result.json ├── pass4_test.json ├── pass5_result.hjson ├── pass5_result.json ├── pass5_test.hjson ├── pass6_result.hjson ├── pass6_result.json ├── pass6_test.hjson ├── passSingle_result.hjson ├── passSingle_result.json ├── passSingle_test.hjson ├── root_result.hjson ├── root_result.json ├── root_test.hjson ├── stringify1_result.hjson ├── stringify1_result.json ├── stringify1_test.hjson ├── strings2_result.hjson ├── strings2_result.json ├── strings2_test.hjson ├── strings_result.hjson ├── strings_result.json ├── strings_test.hjson ├── testlist.txt ├── trail_result.hjson ├── trail_result.json └── trail_test.hjson ├── build.gradle ├── cli ├── bin │ ├── hjson │ └── hjson.bat ├── build.gradle └── src │ └── org.hjson.cli │ └── Main.java ├── docs ├── .gitignore ├── allclasses-frame.html ├── allclasses-noframe.html ├── constant-values.html ├── deprecated-list.html ├── help-doc.html ├── index-all.html ├── index.html ├── org │ └── hjson │ │ ├── HjsonDsf.html │ │ ├── HjsonOptions.html │ │ ├── IHjsonDsfProvider.html │ │ ├── JsonArray.html │ │ ├── JsonObject.Member.html │ │ ├── JsonObject.html │ │ ├── JsonType.html │ │ ├── JsonValue.html │ │ ├── ParseException.html │ │ ├── Stringify.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ └── package-tree.html ├── overview-tree.html ├── script.js ├── serialized-form.html └── stylesheet.css ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── history.md ├── settings.gradle └── src ├── main └── org │ └── hjson │ ├── HjsonDsf.java │ ├── HjsonOptions.java │ ├── HjsonParser.java │ ├── HjsonWriter.java │ ├── IHjsonDsfProvider.java │ ├── JsonArray.java │ ├── JsonDsf.java │ ├── JsonLiteral.java │ ├── JsonNumber.java │ ├── JsonObject.java │ ├── JsonParser.java │ ├── JsonString.java │ ├── JsonType.java │ ├── JsonValue.java │ ├── JsonWriter.java │ ├── ParseException.java │ ├── Stringify.java │ └── WritingBuffer.java └── test └── org └── hjson └── test ├── Main.java └── TestFunctions.java /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Publish hjson-java releases on Maven 2 | on: 3 | workflow_dispatch: 4 | release: 5 | types: [released] 6 | jobs: 7 | publish: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v3 11 | - name: Set up Java 12 | uses: actions/setup-java@v3 13 | with: 14 | distribution: 'temurin' 15 | java-version: '8' 16 | - name: Validate Gradle wrapper 17 | uses: gradle/wrapper-validation-action@ccb4328a959376b642e027874838f60f8e596de3 18 | - name: Publish package 19 | uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629 20 | with: 21 | arguments: publish 22 | env: 23 | GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }} 24 | GPG_SIGNING_PASSWORD: ${{ secrets.GPG_SIGNING_PASSWORD }} 25 | MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} 26 | MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} 27 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: test 2 | on: [push, pull_request] 3 | jobs: 4 | test: 5 | runs-on: ${{ matrix.os }} 6 | strategy: 7 | fail-fast: false 8 | matrix: 9 | os: [ubuntu-latest] 10 | steps: 11 | - uses: actions/checkout@v3 12 | - name: Set up JDK 8 13 | uses: actions/setup-java@v3 14 | with: 15 | distribution: 'temurin' 16 | java-version: '8' 17 | - run: java -version 18 | - run: ./gradlew -version 19 | - run: ./gradlew test --warning-mode all 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle/ 3 | build/ 4 | 5 | # IntelliJ 6 | *.iml 7 | .idea 8 | 9 | # Eclipse 10 | .project 11 | .classpath 12 | .settings/ 13 | 14 | # MacOS 15 | .DS_Store 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013, 2014 EclipseSource 4 | Copyright (c) 2015-2016 Christian Zangl 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hjson-java 2 | 3 | [![Build Status](https://github.com/hjson/hjson-java/workflows/test/badge.svg)](https://github.com/hjson/hjson-java/actions) 4 | [![Maven Central](https://img.shields.io/maven-central/v/org.hjson/hjson.svg?style=flat-square)](http://search.maven.org/#search|ga|1|g%3A%22org.hjson%22%20a%3A%22hjson%22) 5 | [![Javadoc](https://img.shields.io/badge/Javadoc-blue)](http://www.javadoc.io/doc/org.hjson/hjson) 6 | 7 | [Hjson](https://hjson.github.io), the Human JSON. A configuration file format for humans. Relaxed syntax, fewer mistakes, more comments. 8 | 9 | ![Hjson Intro](https://hjson.github.io/hjson1.gif) 10 | 11 | ``` 12 | { 13 | # specify rate in requests/second (because comments are helpful!) 14 | rate: 1000 15 | 16 | // prefer c-style comments? 17 | /* feeling old fashioned? */ 18 | 19 | # did you notice that rate doesn't need quotes? 20 | hey: look ma, no quotes for strings either! 21 | 22 | # best of all 23 | notice: [] 24 | anything: ? 25 | 26 | # yes, commas are optional! 27 | } 28 | ``` 29 | 30 | The Java implementation of Hjson is based on [minimal-json](https://github.com/ralfstx/minimal-json). For other platforms see [hjson.github.io](https://hjson.github.io). 31 | 32 | # CLI 33 | 34 | You can install the Hjson command line tool by downloading and unpacking the latest [*hjson.zip*](https://github.com/hjson/hjson-java/releases). 35 | 36 | - run `hjson -h` for help 37 | - `hjson file.json` will convert to Hjson. 38 | - `hjson -j file.hjson` will convert to JSON. 39 | 40 | # Install from Maven Central 41 | 42 | ## Gradle 43 | 44 | Add a dependency to your `build.gradle`: 45 | 46 | ``` 47 | dependencies { 48 | compile 'org.hjson:hjson:3.1.0' 49 | } 50 | ``` 51 | 52 | ## Maven 53 | 54 | Add a dependency to your `pom.xml`: 55 | 56 | ```xml 57 | 58 | org.hjson 59 | hjson 60 | 3.1.0 61 | 62 | ``` 63 | 64 | ## Ivy 65 | 66 | Add a dependency to your `ivy.xml`: 67 | 68 | ```xml 69 | 70 | 71 | 72 | ``` 73 | 74 | # Usage 75 | 76 | You can either 77 | 78 | - use this libary directly 79 | - or just convert Hjson to JSON and use it with your *favorite JSON library*. 80 | 81 | ### Convert 82 | 83 | ```java 84 | // convert Hjson to JSON 85 | String jsonString = JsonValue.readHjson(readerOrHjsonString).toString(); 86 | 87 | // convert JSON to Hjson 88 | String hjsonString = JsonValue.readHjson(readerOrJSONString).toString(Stringify.HJSON); 89 | ``` 90 | 91 | ### Read 92 | 93 | ```java 94 | JsonObject jsonObject = JsonValue.readHjson(string).asObject(); 95 | JsonArray jsonArray = JsonValue.readHjson(reader).asArray(); 96 | ``` 97 | 98 | `JsonValue.readHjson()` will accept both Hjson and JSON. You can use `JsonValue.readJSON()` to accept JSON input only. 99 | 100 | ### Object sample 101 | 102 | ```java 103 | String name = jsonObject.get("name").asString(); 104 | int age = jsonObject.get("age").asInt(); // asLong(), asFloat(), asDouble(), ... 105 | 106 | // or iterate over the members 107 | for (Member member : jsonObject) { 108 | String name = member.getName(); 109 | JsonValue value = member.getValue(); 110 | // ... 111 | } 112 | ``` 113 | 114 | ### Array sample 115 | 116 | ```java 117 | String name = jsonArray.get(0).asString(); 118 | int age = jsonArray.get(1).asInt(); // asLong(), asFloat(), asDouble(), ... 119 | 120 | // or iterate over the values 121 | for(JsonValue value : jsonArray) { 122 | // ... 123 | } 124 | ``` 125 | 126 | ### Nested sample 127 | 128 | ```java 129 | // Example: { "friends": [ { "name": "John", "age": 23 }, ... ], ... } 130 | JsonArray friends = jsonObject.get("friends").asArray(); 131 | String name = friends.get(0).asObject().get("name").asString(); 132 | int age = friends.get(0).asObject().get("age").asInt(); 133 | ``` 134 | 135 | ### Create 136 | 137 | ```java 138 | JsonObject jsonObject = new JsonObject().add("name", "John").add("age", 23); 139 | // -> { "name": "John", "age", 23 } 140 | 141 | JsonArray jsonArray = new JsonArray().add("John").add(23); 142 | // -> [ "John", 23 ] 143 | ``` 144 | 145 | ### Modify 146 | 147 | ```java 148 | jsonObject.set("age", 24); 149 | jsonArray.set(1, 24); // access element by index 150 | 151 | jsonObject.remove("age"); 152 | jsonArray.remove(1); 153 | ``` 154 | 155 | ### Write 156 | 157 | Writing is not buffered (to avoid buffering twice), so you *should* use a BufferedWriter. 158 | 159 | ```java 160 | jsonObject.writeTo(writer); 161 | jsonObject.writeTo(writer, Stringify.HJSON); 162 | ``` 163 | 164 | ### toString() 165 | 166 | ```java 167 | jsonObject.toString(Stringify.HJSON); // Hjson output 168 | jsonObject.toString(Stringify.FORMATTED); // formatted JSON output 169 | jsonObject.toString(Stringify.PLAIN); // plain JSON output, default 170 | jsonObject.toString(); // plain 171 | ``` 172 | 173 | # API 174 | 175 | [Documentation](https://hjson.github.io/hjson-java/) 176 | 177 | # History 178 | 179 | [see history.md](history.md) 180 | -------------------------------------------------------------------------------- /assets/charset2_result.hjson: -------------------------------------------------------------------------------- 1 | { 2 | uescape: "\u0000,\u0001,\uffff" 3 | "um\u000blaut": äöüßÄÖÜ 4 | hex: ģ䕧覫췯ꯍ 5 | } -------------------------------------------------------------------------------- /assets/charset2_result.json: -------------------------------------------------------------------------------- 1 | { 2 | "uescape": "\u0000,\u0001,\uffff", 3 | "um\u000blaut": "äöüßÄÖÜ", 4 | "hex": "ģ䕧覫췯ꯍ" 5 | } -------------------------------------------------------------------------------- /assets/charset2_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | uescape: "\u0000,\u0001,\uffff" 3 | "um\u000blaut": äöüßÄÖÜ 4 | hex: "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A" 5 | } -------------------------------------------------------------------------------- /assets/charset_result.hjson: -------------------------------------------------------------------------------- 1 | { 2 | ql-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ 3 | js-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ 4 | ml-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ 5 | } -------------------------------------------------------------------------------- /assets/charset_result.json: -------------------------------------------------------------------------------- 1 | { 2 | "ql-ascii": "! \"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", 3 | "js-ascii": "! \"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", 4 | "ml-ascii": "! \"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" 5 | } -------------------------------------------------------------------------------- /assets/charset_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | ql-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ 3 | js-ascii: "! \"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" 4 | ml-ascii: 5 | ''' 6 | ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ 7 | ''' 8 | } 9 | -------------------------------------------------------------------------------- /assets/comments2_result.hjson: -------------------------------------------------------------------------------- 1 | 3 -------------------------------------------------------------------------------- /assets/comments2_result.json: -------------------------------------------------------------------------------- 1 | 3 -------------------------------------------------------------------------------- /assets/comments2_test.hjson: -------------------------------------------------------------------------------- 1 | // before 2 | /* before2 */ 3 // after1 3 | // after2 -------------------------------------------------------------------------------- /assets/comments3_result.hjson: -------------------------------------------------------------------------------- 1 | a string value // still part of the string -------------------------------------------------------------------------------- /assets/comments3_result.json: -------------------------------------------------------------------------------- 1 | "a string value // still part of the string" -------------------------------------------------------------------------------- /assets/comments3_test.hjson: -------------------------------------------------------------------------------- 1 | // before 2 | /* before2 */ a string value // still part of the string 3 | // after2 -------------------------------------------------------------------------------- /assets/comments4_result.hjson: -------------------------------------------------------------------------------- 1 | [ 2 | a string value // still part of the string 3 | a string value 4 | {} 5 | {} 6 | {} 7 | [] 8 | {} 9 | { 10 | val5a: 1 11 | val5b: 2 12 | } 13 | [] 14 | [] 15 | [] 16 | [] 17 | [ 18 | 1 19 | 2 20 | ] 21 | 3 22 | 4 23 | ] -------------------------------------------------------------------------------- /assets/comments4_result.json: -------------------------------------------------------------------------------- 1 | [ 2 | "a string value // still part of the string", 3 | "a string value", 4 | {}, 5 | {}, 6 | {}, 7 | [], 8 | {}, 9 | { 10 | "val5a": 1, 11 | "val5b": 2 12 | }, 13 | [], 14 | [], 15 | [], 16 | [], 17 | [ 18 | 1, 19 | 2 20 | ], 21 | 3, 22 | 4 23 | ] -------------------------------------------------------------------------------- /assets/comments4_test.hjson: -------------------------------------------------------------------------------- 1 | // before 2 | /* before2 */ [ #before1 3 | /*key1keycm*/a string value // still part of the string 4 | /* key2keycm */ "a string value" // not part of the string 5 | // map1before 6 | /* map1key */ 7 | {}//map2after 8 | {} 9 | { 10 | // map3 inner comment 11 | } 12 | [] 13 | // map4before 14 | /*map4key*/{ 15 | /* map4inner */ 16 | } // map4after 17 | //map5before 18 | /*map5key*/ { 19 | //map5ab4 20 | val5a: /* map5akey */ 1, // map5aAfter 21 | val5b: 2 /* map5bb4comma */ , #map5bAfter 22 | #map5extra 23 | } /* map5after */ 24 | // vec1bbefore 25 | /* vec1bkey */ 26 | []//vec1bafter 27 | [] 28 | [ 29 | // vec3 inner comment 30 | ] 31 | // vec4before 32 | /*vec4key*/[ 33 | /* vec4inner */ 34 | ] // vec4after 35 | //vec5before 36 | /*vec5key*/ [ 37 | //vec5ab4 38 | 1, // vec5aAfter 39 | 2 /* vec5bb4comma */ , #vec5bAfter 40 | #vec5extra 41 | ] /* map5after */ 42 | // before3 43 | 44 | 3 # after3 45 | # before4 46 | /*before4b*/4/*after4*/ 47 | #after4b 48 | ] 49 | // after2 50 | 51 | /* after3 */ -------------------------------------------------------------------------------- /assets/comments5_result.hjson: -------------------------------------------------------------------------------- 1 | { 2 | key1: a string value // still part of the string 3 | key2: a string value 4 | map1: {} 5 | map2: {} 6 | map3: {} 7 | vec1: [] 8 | map4: {} 9 | map5: 10 | { 11 | val5a: 1 12 | val5b: 2 13 | } 14 | vec1b: [] 15 | vec2: [] 16 | vec3: [] 17 | vec4: [] 18 | vec5: 19 | [ 20 | 1 21 | 2 22 | ] 23 | key3: 3 24 | key4: 4 25 | } -------------------------------------------------------------------------------- /assets/comments5_result.json: -------------------------------------------------------------------------------- 1 | { 2 | "key1": "a string value // still part of the string", 3 | "key2": "a string value", 4 | "map1": {}, 5 | "map2": {}, 6 | "map3": {}, 7 | "vec1": [], 8 | "map4": {}, 9 | "map5": { 10 | "val5a": 1, 11 | "val5b": 2 12 | }, 13 | "vec1b": [], 14 | "vec2": [], 15 | "vec3": [], 16 | "vec4": [], 17 | "vec5": [ 18 | 1, 19 | 2 20 | ], 21 | "key3": 3, 22 | "key4": 4 23 | } -------------------------------------------------------------------------------- /assets/comments5_test.hjson: -------------------------------------------------------------------------------- 1 | // before 2 | /* before2 */ { #before1 3 | key1:/*key1keycm*/a string value // still part of the string 4 | key2: /* key2keycm */ "a string value" // not part of the string 5 | // map1before 6 | map1: /* map1key */ 7 | {}//map2after 8 | map2: {} 9 | map3: { 10 | // map3 inner comment 11 | } 12 | vec1: [] 13 | // map4before 14 | map4:/*map4key*/{ 15 | /* map4inner */ 16 | } // map4after 17 | //map5before 18 | map5: /*map5key*/ { 19 | //map5ab4 20 | val5a: /* map5akey */ 1, // map5aAfter 21 | val5b: 2 /* map5bb4comma */ , #map5bAfter 22 | #map5extra 23 | } /* map5after */ 24 | // vec1bbefore 25 | vec1b: /* vec1bkey */ 26 | []//vec1bafter 27 | vec2: [] 28 | vec3: [ 29 | // vec3 inner comment 30 | ] 31 | // vec4before 32 | vec4:/*vec4key*/[ 33 | /* vec4inner */ 34 | ] // vec4after 35 | //vec5before 36 | vec5: /*vec5key*/ [ 37 | //vec5ab4 38 | 1, // vec5aAfter 39 | 2 /* vec5bb4comma */ , #vec5bAfter 40 | #vec5extra 41 | ] /* map5after */ 42 | // before3 43 | 44 | key3 : 3 # after3 45 | # before4 46 | /*before4b*/key4:4/*after4*/ 47 | #after4b 48 | } 49 | // after2 50 | 51 | /* after3 */ -------------------------------------------------------------------------------- /assets/comments6_result.hjson: -------------------------------------------------------------------------------- 1 | 3 -------------------------------------------------------------------------------- /assets/comments6_result.json: -------------------------------------------------------------------------------- 1 | 3 -------------------------------------------------------------------------------- /assets/comments6_test.hjson: -------------------------------------------------------------------------------- 1 | // before 2 | /* before2 */ 3 // after1 3 | // after2 -------------------------------------------------------------------------------- /assets/comments7_result.hjson: -------------------------------------------------------------------------------- 1 | { 2 | b: 3 | { 4 | sub1: 3 5 | sub2: 4 6 | } 7 | a: 2 8 | } -------------------------------------------------------------------------------- /assets/comments7_result.json: -------------------------------------------------------------------------------- 1 | { 2 | "b": { 3 | "sub1": 3, 4 | "sub2": 4 5 | }, 6 | "a": 2 7 | } -------------------------------------------------------------------------------- /assets/comments7_test.hjson: -------------------------------------------------------------------------------- 1 | # comment before 2 | b: /* key comment */ { 3 | sub1: 3 # comment after 4 | sub2: 4 # comment more after 5 | } # cm after obj 6 | // Comment B4 7 | a: 2 8 | /* Last comment */ 9 | -------------------------------------------------------------------------------- /assets/comments_result.hjson: -------------------------------------------------------------------------------- 1 | { 2 | foo1: This is a string value. # part of the string 3 | foo2: This is a string value. 4 | bar1: This is a string value. // part of the string 5 | bar2: This is a string value. 6 | foobar1: This is a string value./* part of the string */ 7 | foobar2: This is a string value. 8 | rem1: "# test" 9 | rem2: "// test" 10 | rem3: "/* test */" 11 | num1: 0 12 | num2: 0 13 | num3: 2 14 | true1: true 15 | true2: true 16 | true3: true 17 | false1: false 18 | false2: false 19 | false3: false 20 | null1: null 21 | null2: null 22 | null3: null 23 | str1: 00 # part of the string 24 | str2: 00.0 // part of the string 25 | str3: 02 /* part of the string */ 26 | } -------------------------------------------------------------------------------- /assets/comments_result.json: -------------------------------------------------------------------------------- 1 | { 2 | "foo1": "This is a string value. # part of the string", 3 | "foo2": "This is a string value.", 4 | "bar1": "This is a string value. // part of the string", 5 | "bar2": "This is a string value.", 6 | "foobar1": "This is a string value./* part of the string */", 7 | "foobar2": "This is a string value.", 8 | "rem1": "# test", 9 | "rem2": "// test", 10 | "rem3": "/* test */", 11 | "num1": 0, 12 | "num2": 0, 13 | "num3": 2, 14 | "true1": true, 15 | "true2": true, 16 | "true3": true, 17 | "false1": false, 18 | "false2": false, 19 | "false3": false, 20 | "null1": null, 21 | "null2": null, 22 | "null3": null, 23 | "str1": "00 # part of the string", 24 | "str2": "00.0 // part of the string", 25 | "str3": "02 /* part of the string */" 26 | } -------------------------------------------------------------------------------- /assets/comments_test.hjson: -------------------------------------------------------------------------------- 1 | // test 2 | # all 3 | // comment 4 | /* 5 | styles 6 | */ 7 | # with lf 8 | 9 | 10 | 11 | # ! 12 | 13 | { 14 | # hjson style comment 15 | foo1: This is a string value. # part of the string 16 | foo2: "This is a string value." # a comment 17 | 18 | // js style comment 19 | bar1: This is a string value. // part of the string 20 | bar2: "This is a string value." // a comment 21 | 22 | /* js block style comments */foobar1:/* more */This is a string value./* part of the string */ 23 | /* js block style comments */foobar2:/* more */"This is a string value."/* a comment */ 24 | 25 | rem1: "# test" 26 | rem2: "// test" 27 | rem3: "/* test */" 28 | 29 | num1: 0 # comment 30 | num2: 0.0 // comment 31 | num3: 2 /* comment */ 32 | 33 | true1: true # comment 34 | true2: true // comment 35 | true3: true /* comment */ 36 | 37 | false1: false # comment 38 | false2: false // comment 39 | false3: false /* comment */ 40 | 41 | null1: null # comment 42 | null2: null // comment 43 | null3: null /* comment */ 44 | 45 | str1: 00 # part of the string 46 | str2: 00.0 // part of the string 47 | str3: 02 /* part of the string */ 48 | } 49 | -------------------------------------------------------------------------------- /assets/empty_result.hjson: -------------------------------------------------------------------------------- 1 | { 2 | "": empty 3 | } -------------------------------------------------------------------------------- /assets/empty_result.json: -------------------------------------------------------------------------------- 1 | { 2 | "": "empty" 3 | } -------------------------------------------------------------------------------- /assets/empty_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | "": empty 3 | } 4 | -------------------------------------------------------------------------------- /assets/failCharset1_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # invalid \u char 3 | char: "\uxxxx" 4 | } 5 | -------------------------------------------------------------------------------- /assets/failJSON02_test.json: -------------------------------------------------------------------------------- 1 | ["Unclosed array" -------------------------------------------------------------------------------- /assets/failJSON05_test.json: -------------------------------------------------------------------------------- 1 | ["double extra comma",,] -------------------------------------------------------------------------------- /assets/failJSON06_test.json: -------------------------------------------------------------------------------- 1 | [ , "<-- missing value"] -------------------------------------------------------------------------------- /assets/failJSON07_test.json: -------------------------------------------------------------------------------- 1 | ["Comma after the close"], -------------------------------------------------------------------------------- /assets/failJSON08_test.json: -------------------------------------------------------------------------------- 1 | ["Extra close"]] -------------------------------------------------------------------------------- /assets/failJSON10_test.json: -------------------------------------------------------------------------------- 1 | {"Extra value after close": true} "misplaced quoted value" -------------------------------------------------------------------------------- /assets/failJSON11_test.json: -------------------------------------------------------------------------------- 1 | {"Illegal expression": 1 + 2} -------------------------------------------------------------------------------- /assets/failJSON12_test.json: -------------------------------------------------------------------------------- 1 | {"Illegal invocation": alert()} -------------------------------------------------------------------------------- /assets/failJSON13_test.json: -------------------------------------------------------------------------------- 1 | {"Numbers cannot have leading zeroes": 013} -------------------------------------------------------------------------------- /assets/failJSON14_test.json: -------------------------------------------------------------------------------- 1 | {"Numbers cannot be hex": 0x14} -------------------------------------------------------------------------------- /assets/failJSON15_test.json: -------------------------------------------------------------------------------- 1 | ["Illegal backslash escape: \x15"] -------------------------------------------------------------------------------- /assets/failJSON16_test.json: -------------------------------------------------------------------------------- 1 | [\naked] -------------------------------------------------------------------------------- /assets/failJSON17_test.json: -------------------------------------------------------------------------------- 1 | ["Illegal backslash escape: \017"] -------------------------------------------------------------------------------- /assets/failJSON19_test.json: -------------------------------------------------------------------------------- 1 | {"Missing colon" null} -------------------------------------------------------------------------------- /assets/failJSON20_test.json: -------------------------------------------------------------------------------- 1 | {"Double colon":: null} -------------------------------------------------------------------------------- /assets/failJSON21_test.json: -------------------------------------------------------------------------------- 1 | {"Comma instead of colon", null} -------------------------------------------------------------------------------- /assets/failJSON22_test.json: -------------------------------------------------------------------------------- 1 | ["Colon instead of comma": false] -------------------------------------------------------------------------------- /assets/failJSON23_test.json: -------------------------------------------------------------------------------- 1 | ["Bad value", truth] -------------------------------------------------------------------------------- /assets/failJSON26_test.json: -------------------------------------------------------------------------------- 1 | ["tab\ character\ in\ string\ "] -------------------------------------------------------------------------------- /assets/failJSON28_test.json: -------------------------------------------------------------------------------- 1 | ["line\ 2 | break"] -------------------------------------------------------------------------------- /assets/failJSON29_test.json: -------------------------------------------------------------------------------- 1 | [0e] -------------------------------------------------------------------------------- /assets/failJSON30_test.json: -------------------------------------------------------------------------------- 1 | [0e+] -------------------------------------------------------------------------------- /assets/failJSON31_test.json: -------------------------------------------------------------------------------- 1 | [0e+-1] -------------------------------------------------------------------------------- /assets/failJSON32_test.json: -------------------------------------------------------------------------------- 1 | {"Comma instead if closing brace": true, -------------------------------------------------------------------------------- /assets/failJSON33_test.json: -------------------------------------------------------------------------------- 1 | ["mismatch"} -------------------------------------------------------------------------------- /assets/failJSON34_test.json: -------------------------------------------------------------------------------- 1 | A quoteless string is OK, 2 | but two must be contained in an array. 3 | -------------------------------------------------------------------------------- /assets/failKey1_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # invalid name 3 | wrong name: 0 4 | } 5 | -------------------------------------------------------------------------------- /assets/failKey2_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # invalid name 3 | {name: 0 4 | } 5 | -------------------------------------------------------------------------------- /assets/failKey3_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # invalid name 3 | key,name: 0 4 | } 5 | -------------------------------------------------------------------------------- /assets/failKey4_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # invalid name 3 | : 0 4 | } 5 | -------------------------------------------------------------------------------- /assets/failKey5_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # invalid name 3 | '''foo''': 0 4 | } 5 | -------------------------------------------------------------------------------- /assets/failMLStr1_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # invalid multiline string 3 | ml: ''' 4 | -------------------------------------------------------------------------------- /assets/failObj1_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # invalid obj 3 | noDelimiter 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /assets/failObj2_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # invalid obj 3 | noEnd 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /assets/failObj3_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # missing key 3 | 4 | [ 5 | test 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /assets/failStr1a_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # invalid quoteless string 3 | ql: ] 4 | } 5 | -------------------------------------------------------------------------------- /assets/failStr1b_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # invalid quoteless string 3 | ql: ]x 4 | } 5 | -------------------------------------------------------------------------------- /assets/failStr1c_test.hjson: -------------------------------------------------------------------------------- 1 | [ 2 | foo 3 | # invalid quoteless string 4 | ] 5 | ] 6 | -------------------------------------------------------------------------------- /assets/failStr1d_test.hjson: -------------------------------------------------------------------------------- 1 | [ 2 | foo 3 | # invalid quoteless string 4 | ]x 5 | ] 6 | -------------------------------------------------------------------------------- /assets/failStr2a_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # invalid quoteless string 3 | ql: } 4 | } 5 | -------------------------------------------------------------------------------- /assets/failStr2b_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # invalid quoteless string 3 | ql: }x 4 | } 5 | -------------------------------------------------------------------------------- /assets/failStr2c_test.hjson: -------------------------------------------------------------------------------- 1 | [ 2 | foo 3 | # invalid quoteless string 4 | } 5 | ] 6 | -------------------------------------------------------------------------------- /assets/failStr2d_test.hjson: -------------------------------------------------------------------------------- 1 | [ 2 | foo 3 | # invalid quoteless string 4 | }x 5 | ] 6 | -------------------------------------------------------------------------------- /assets/failStr3a_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # invalid quoteless string 3 | ql: { 4 | } 5 | -------------------------------------------------------------------------------- /assets/failStr3b_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # invalid quoteless string 3 | ql: {x 4 | } 5 | -------------------------------------------------------------------------------- /assets/failStr3c_test.hjson: -------------------------------------------------------------------------------- 1 | [ 2 | foo 3 | # invalid quoteless string 4 | { 5 | ] 6 | -------------------------------------------------------------------------------- /assets/failStr3d_test.hjson: -------------------------------------------------------------------------------- 1 | [ 2 | foo 3 | # invalid quoteless string 4 | {x 5 | ] 6 | -------------------------------------------------------------------------------- /assets/failStr4a_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # invalid quoteless string 3 | ql: [ 4 | } 5 | -------------------------------------------------------------------------------- /assets/failStr4b_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # invalid quoteless string 3 | ql: [x 4 | } 5 | -------------------------------------------------------------------------------- /assets/failStr4c_test.hjson: -------------------------------------------------------------------------------- 1 | [ 2 | foo 3 | # invalid quoteless string 4 | [ 5 | ] 6 | -------------------------------------------------------------------------------- /assets/failStr4d_test.hjson: -------------------------------------------------------------------------------- 1 | [ 2 | foo 3 | # invalid quoteless string 4 | [x 5 | ] 6 | -------------------------------------------------------------------------------- /assets/failStr5a_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # invalid quoteless string 3 | ql: : 4 | } 5 | -------------------------------------------------------------------------------- /assets/failStr5b_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # invalid quoteless string 3 | ql: :x 4 | } 5 | -------------------------------------------------------------------------------- /assets/failStr5c_test.hjson: -------------------------------------------------------------------------------- 1 | [ 2 | foo 3 | # invalid quoteless string 4 | : 5 | ] 6 | -------------------------------------------------------------------------------- /assets/failStr5d_test.hjson: -------------------------------------------------------------------------------- 1 | [ 2 | foo 3 | # invalid quoteless string 4 | :x 5 | ] 6 | -------------------------------------------------------------------------------- /assets/failStr6a_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # invalid quoteless string 3 | ql: , 4 | } 5 | -------------------------------------------------------------------------------- /assets/failStr6b_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # invalid quoteless string 3 | ql: ,x 4 | } 5 | -------------------------------------------------------------------------------- /assets/failStr6c_test.hjson: -------------------------------------------------------------------------------- 1 | [ 2 | # invalid quoteless string 3 | # note that if there were a preceding value the comma would 4 | # be allowed/ignored as a separator/trailing comma 5 | , 6 | ] 7 | -------------------------------------------------------------------------------- /assets/failStr6d_test.hjson: -------------------------------------------------------------------------------- 1 | [ 2 | # invalid quoteless string 3 | # note that if there were a preceding value the comma would 4 | # be allowed/ignored as a separator/trailing comma 5 | ,x 6 | ] 7 | -------------------------------------------------------------------------------- /assets/failStr7a_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # invalid string containing a newline 3 | foo : " 4 | " 5 | } 6 | -------------------------------------------------------------------------------- /assets/failStr8a_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # invalid ml-string 3 | foo : ""'text''' 4 | } 5 | -------------------------------------------------------------------------------- /assets/kan_result.hjson: -------------------------------------------------------------------------------- 1 | { 2 | numbers: 3 | [ 4 | 0 5 | 0 6 | 0 7 | 42 8 | 42.1 9 | -5 10 | -5.1 11 | 1701 12 | -1701 13 | 12.345 14 | -12.345 15 | ] 16 | native: 17 | [ 18 | true 19 | true 20 | false 21 | false 22 | null 23 | null 24 | ] 25 | strings: 26 | [ 27 | x 0 28 | .0 29 | 00 30 | 01 31 | 0 0 0 32 | 42 x 33 | 42.1 asdf 34 | 1.2.3 35 | -5 0 - 36 | -5.1 -- 37 | 17.01e2 + 38 | -17.01e2 : 39 | 12345e-3 @ 40 | -12345e-3 $ 41 | true true 42 | x true 43 | false false 44 | x false 45 | null null 46 | x null 47 | ] 48 | } -------------------------------------------------------------------------------- /assets/kan_result.json: -------------------------------------------------------------------------------- 1 | { 2 | "numbers": [ 3 | 0, 4 | 0, 5 | 0, 6 | 42, 7 | 42.1, 8 | -5, 9 | -5.1, 10 | 1701, 11 | -1701, 12 | 12.345, 13 | -12.345 14 | ], 15 | "native": [ 16 | true, 17 | true, 18 | false, 19 | false, 20 | null, 21 | null 22 | ], 23 | "strings": [ 24 | "x 0", 25 | ".0", 26 | "00", 27 | "01", 28 | "0 0 0", 29 | "42 x", 30 | "42.1 asdf", 31 | "1.2.3", 32 | "-5 0 -", 33 | "-5.1 --", 34 | "17.01e2 +", 35 | "-17.01e2 :", 36 | "12345e-3 @", 37 | "-12345e-3 $", 38 | "true true", 39 | "x true", 40 | "false false", 41 | "x false", 42 | "null null", 43 | "x null" 44 | ] 45 | } -------------------------------------------------------------------------------- /assets/kan_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # the comma forces a whitespace check 3 | numbers: 4 | [ 5 | 0 6 | 0 , 7 | -0 8 | 42 , 9 | 42.1 , 10 | -5 11 | -5.1 12 | 17.01e2 13 | -17.01e2 14 | 12345e-3 , 15 | -12345e-3 , 16 | ] 17 | native: 18 | [ 19 | true , 20 | true 21 | false , 22 | false 23 | null , 24 | null 25 | ] 26 | strings: 27 | [ 28 | x 0 29 | .0 30 | 00 31 | 01 32 | 0 0 0 33 | 42 x 34 | 42.1 asdf 35 | 1.2.3 36 | -5 0 - 37 | -5.1 -- 38 | 17.01e2 + 39 | -17.01e2 : 40 | 12345e-3 @ 41 | -12345e-3 $ 42 | true true 43 | x true 44 | false false 45 | x false 46 | null null 47 | x null 48 | ] 49 | } 50 | -------------------------------------------------------------------------------- /assets/keys_result.hjson: -------------------------------------------------------------------------------- 1 | { 2 | unquoted_key: test 3 | _unquoted: test 4 | test-key: test 5 | -test: test 6 | .key: test 7 | trailing: test 8 | trailing2: test 9 | "#c1": test 10 | "foo#bar": test 11 | "//bar": test 12 | "foo//bar": test 13 | "/*foo*/": test 14 | "foo/*foo*/bar": test 15 | "/*": test 16 | "foo/*bar": test 17 | "\"": test 18 | "foo\"bar": test 19 | "'''": test 20 | "foo'''bar": test 21 | "'": test 22 | "'foo": test 23 | "foo'bar": test 24 | ":": test 25 | "foo:bar": test 26 | "{": test 27 | "foo{bar": test 28 | "}": test 29 | "foo}bar": test 30 | "[": test 31 | "foo[bar": test 32 | "]": test 33 | "foo]bar": test 34 | nl1: test 35 | nl2: test 36 | nl3: test 37 | } -------------------------------------------------------------------------------- /assets/keys_result.json: -------------------------------------------------------------------------------- 1 | { 2 | "unquoted_key": "test", 3 | "_unquoted": "test", 4 | "test-key": "test", 5 | "-test": "test", 6 | ".key": "test", 7 | "trailing": "test", 8 | "trailing2": "test", 9 | "#c1": "test", 10 | "foo#bar": "test", 11 | "//bar": "test", 12 | "foo//bar": "test", 13 | "/*foo*/": "test", 14 | "foo/*foo*/bar": "test", 15 | "/*": "test", 16 | "foo/*bar": "test", 17 | "\"": "test", 18 | "foo\"bar": "test", 19 | "'''": "test", 20 | "foo'''bar": "test", 21 | "'": "test", 22 | "'foo": "test", 23 | "foo'bar": "test", 24 | ":": "test", 25 | "foo:bar": "test", 26 | "{": "test", 27 | "foo{bar": "test", 28 | "}": "test", 29 | "foo}bar": "test", 30 | "[": "test", 31 | "foo[bar": "test", 32 | "]": "test", 33 | "foo]bar": "test", 34 | "nl1": "test", 35 | "nl2": "test", 36 | "nl3": "test" 37 | } -------------------------------------------------------------------------------- /assets/keys_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # unquoted keys 3 | unquoted_key: test 4 | _unquoted: test 5 | test-key: test 6 | -test: test 7 | .key: test 8 | # trailing spaces in key names are ignored 9 | trailing : test 10 | trailing2 : test 11 | # comment char in key name 12 | "#c1": test 13 | "foo#bar": test 14 | "//bar": test 15 | "foo//bar": test 16 | "/*foo*/": test 17 | "foo/*foo*/bar": test 18 | "/*": test 19 | "foo/*bar": test 20 | # quotes in key name 21 | "\"": test 22 | "foo\"bar": test 23 | "'''": test 24 | "foo'''bar": test 25 | "'": test 26 | "'foo": test 27 | "foo'bar": test 28 | # control char in key name 29 | ":": test 30 | "foo:bar": test 31 | "{": test 32 | "foo{bar": test 33 | "}": test 34 | "foo}bar": test 35 | "[": test 36 | "foo[bar": test 37 | "]": test 38 | "foo]bar": test 39 | # newline 40 | nl1: 41 | test 42 | nl2 43 | : 44 | test 45 | 46 | nl3 47 | 48 | : 49 | 50 | test 51 | } 52 | -------------------------------------------------------------------------------- /assets/mltabs_result.hjson: -------------------------------------------------------------------------------- 1 | { 2 | foo: 3 | ''' 4 | bar joe 5 | oki doki 6 | two tabs 7 | ''' 8 | } -------------------------------------------------------------------------------- /assets/mltabs_result.json: -------------------------------------------------------------------------------- 1 | { 2 | "foo": "bar\tjoe\noki\tdoki\n\t\ttwo tabs" 3 | } -------------------------------------------------------------------------------- /assets/mltabs_test.json: -------------------------------------------------------------------------------- 1 | { 2 | "foo": "bar\tjoe\noki\tdoki\n\t\ttwo tabs" 3 | } 4 | -------------------------------------------------------------------------------- /assets/oa_result.hjson: -------------------------------------------------------------------------------- 1 | [ 2 | a 3 | {} 4 | {} 5 | [] 6 | [] 7 | { 8 | b: 1 9 | c: [] 10 | d: {} 11 | } 12 | [] 13 | ] -------------------------------------------------------------------------------- /assets/oa_result.json: -------------------------------------------------------------------------------- 1 | [ 2 | "a", 3 | {}, 4 | {}, 5 | [], 6 | [], 7 | { 8 | "b": 1, 9 | "c": [], 10 | "d": {} 11 | }, 12 | [] 13 | ] -------------------------------------------------------------------------------- /assets/oa_test.hjson: -------------------------------------------------------------------------------- 1 | [ 2 | a 3 | {} 4 | {} 5 | [] 6 | [] 7 | { 8 | b: 1 9 | c: [] 10 | d: {} 11 | } 12 | [] 13 | ] 14 | -------------------------------------------------------------------------------- /assets/pass1_result.hjson: -------------------------------------------------------------------------------- 1 | [ 2 | JSON Test Pattern pass1 3 | { 4 | "object with 1 member": 5 | [ 6 | array with 1 element 7 | ] 8 | } 9 | {} 10 | [] 11 | -42 12 | true 13 | false 14 | null 15 | { 16 | integer: 1234567890 17 | real: -9876.54321 18 | e: 1.23456789e-13 19 | E: 1.23456789e+34 20 | -: 2.3456789012e+76 21 | zero: 0 22 | one: 1 23 | space: " " 24 | quote: '''"''' 25 | backslash: \ 26 | controls: "\b\f\n\r\t" 27 | slash: / & / 28 | alpha: abcdefghijklmnopqrstuvwyz 29 | ALPHA: ABCDEFGHIJKLMNOPQRSTUVWYZ 30 | digit: 0123456789 31 | 0123456789: digit 32 | special: `1~!@#$%^&*()_+-={':[,]}|;.? 33 | hex: ģ䕧覫췯ꯍ 34 | true: true 35 | false: false 36 | null: null 37 | array: [] 38 | object: {} 39 | address: 50 St. James Street 40 | url: http://www.JSON.org/ 41 | comment: "// /* */": " " 43 | " s p a c e d ": 44 | [ 45 | 1 46 | 2 47 | 3 48 | 4 49 | 5 50 | 6 51 | 7 52 | ] 53 | compact: 54 | [ 55 | 1 56 | 2 57 | 3 58 | 4 59 | 5 60 | 6 61 | 7 62 | ] 63 | jsontext: '''{"object with 1 member":["array with 1 element"]}''' 64 | quotes: " " %22 0x22 034 " 65 | "/\\\"쫾몾ꮘﳞ볚\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?": A key can be any string 66 | } 67 | 0.5 68 | 98.6 69 | 99.44 70 | 1066 71 | 10 72 | 1 73 | 0.1 74 | 1 75 | 2 76 | 2 77 | rosebud 78 | ] -------------------------------------------------------------------------------- /assets/pass1_result.json: -------------------------------------------------------------------------------- 1 | [ 2 | "JSON Test Pattern pass1", 3 | { 4 | "object with 1 member": [ 5 | "array with 1 element" 6 | ] 7 | }, 8 | {}, 9 | [], 10 | -42, 11 | true, 12 | false, 13 | null, 14 | { 15 | "integer": 1234567890, 16 | "real": -9876.54321, 17 | "e": 1.23456789e-13, 18 | "E": 1.23456789e+34, 19 | "-": 2.3456789012e+76, 20 | "zero": 0, 21 | "one": 1, 22 | "space": " ", 23 | "quote": "\"", 24 | "backslash": "\\", 25 | "controls": "\b\f\n\r\t", 26 | "slash": "/ & /", 27 | "alpha": "abcdefghijklmnopqrstuvwyz", 28 | "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ", 29 | "digit": "0123456789", 30 | "0123456789": "digit", 31 | "special": "`1~!@#$%^&*()_+-={':[,]}|;.?", 32 | "hex": "ģ䕧覫췯ꯍ", 33 | "true": true, 34 | "false": false, 35 | "null": null, 36 | "array": [], 37 | "object": {}, 38 | "address": "50 St. James Street", 39 | "url": "http://www.JSON.org/", 40 | "comment": "// /* */": " ", 42 | " s p a c e d ": [ 43 | 1, 44 | 2, 45 | 3, 46 | 4, 47 | 5, 48 | 6, 49 | 7 50 | ], 51 | "compact": [ 52 | 1, 53 | 2, 54 | 3, 55 | 4, 56 | 5, 57 | 6, 58 | 7 59 | ], 60 | "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}", 61 | "quotes": "" \" %22 0x22 034 "", 62 | "/\\\"쫾몾ꮘﳞ볚\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?": "A key can be any string" 63 | }, 64 | 0.5, 65 | 98.6, 66 | 99.44, 67 | 1066, 68 | 10, 69 | 1, 70 | 0.1, 71 | 1, 72 | 2, 73 | 2, 74 | "rosebud" 75 | ] -------------------------------------------------------------------------------- /assets/pass1_test.json: -------------------------------------------------------------------------------- 1 | [ 2 | "JSON Test Pattern pass1", 3 | {"object with 1 member":["array with 1 element"]}, 4 | {}, 5 | [], 6 | -42, 7 | true, 8 | false, 9 | null, 10 | { 11 | "integer": 1234567890, 12 | "real": -9876.543210, 13 | "e": 0.123456789e-12, 14 | "E": 1.234567890E+34, 15 | "-": 23456789012E66, 16 | "zero": 0, 17 | "one": 1, 18 | "space": " ", 19 | "quote": "\"", 20 | "backslash": "\\", 21 | "controls": "\b\f\n\r\t", 22 | "slash": "/ & \/", 23 | "alpha": "abcdefghijklmnopqrstuvwyz", 24 | "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ", 25 | "digit": "0123456789", 26 | "0123456789": "digit", 27 | "special": "`1~!@#$%^&*()_+-={':[,]}|;.?", 28 | "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A", 29 | "true": true, 30 | "false": false, 31 | "null": null, 32 | "array":[ ], 33 | "object":{ }, 34 | "address": "50 St. James Street", 35 | "url": "http://www.JSON.org/", 36 | "comment": "// /* */": " ", 38 | " s p a c e d " :[1,2 , 3 39 | 40 | , 41 | 42 | 4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7], 43 | "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}", 44 | "quotes": "" \u0022 %22 0x22 034 "", 45 | "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?" 46 | : "A key can be any string" 47 | }, 48 | 0.5 ,98.6 49 | , 50 | 99.44 51 | , 52 | 53 | 1066, 54 | 1e1, 55 | 0.1e1, 56 | 1e-1, 57 | 1e00,2e+00,2e-00 58 | ,"rosebud"] -------------------------------------------------------------------------------- /assets/pass2_result.hjson: -------------------------------------------------------------------------------- 1 | [ 2 | [ 3 | [ 4 | [ 5 | [ 6 | [ 7 | [ 8 | [ 9 | [ 10 | [ 11 | [ 12 | [ 13 | [ 14 | [ 15 | [ 16 | [ 17 | [ 18 | [ 19 | [ 20 | Not too deep 21 | ] 22 | ] 23 | ] 24 | ] 25 | ] 26 | ] 27 | ] 28 | ] 29 | ] 30 | ] 31 | ] 32 | ] 33 | ] 34 | ] 35 | ] 36 | ] 37 | ] 38 | ] 39 | ] -------------------------------------------------------------------------------- /assets/pass2_result.json: -------------------------------------------------------------------------------- 1 | [ 2 | [ 3 | [ 4 | [ 5 | [ 6 | [ 7 | [ 8 | [ 9 | [ 10 | [ 11 | [ 12 | [ 13 | [ 14 | [ 15 | [ 16 | [ 17 | [ 18 | [ 19 | [ 20 | "Not too deep" 21 | ] 22 | ] 23 | ] 24 | ] 25 | ] 26 | ] 27 | ] 28 | ] 29 | ] 30 | ] 31 | ] 32 | ] 33 | ] 34 | ] 35 | ] 36 | ] 37 | ] 38 | ] 39 | ] -------------------------------------------------------------------------------- /assets/pass2_test.json: -------------------------------------------------------------------------------- 1 | [[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]] -------------------------------------------------------------------------------- /assets/pass3_result.hjson: -------------------------------------------------------------------------------- 1 | { 2 | "JSON Test Pattern pass3": 3 | { 4 | "The outermost value": must be an object or array. 5 | "In this test": It is an object. 6 | } 7 | } -------------------------------------------------------------------------------- /assets/pass3_result.json: -------------------------------------------------------------------------------- 1 | { 2 | "JSON Test Pattern pass3": { 3 | "The outermost value": "must be an object or array.", 4 | "In this test": "It is an object." 5 | } 6 | } -------------------------------------------------------------------------------- /assets/pass3_test.json: -------------------------------------------------------------------------------- 1 | { 2 | "JSON Test Pattern pass3": { 3 | "The outermost value": "must be an object or array.", 4 | "In this test": "It is an object." 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /assets/pass4_result.hjson: -------------------------------------------------------------------------------- 1 | 10 -------------------------------------------------------------------------------- /assets/pass4_result.json: -------------------------------------------------------------------------------- 1 | 10 -------------------------------------------------------------------------------- /assets/pass4_test.json: -------------------------------------------------------------------------------- 1 | 2 | 10 3 | -------------------------------------------------------------------------------- /assets/pass5_result.hjson: -------------------------------------------------------------------------------- 1 | { 2 | bigDouble: 9.223372036854776e+58 3 | bigInt: 9.223372036854776e+58 4 | } -------------------------------------------------------------------------------- /assets/pass5_result.json: -------------------------------------------------------------------------------- 1 | { 2 | "bigDouble": 9.223372036854776e+58, 3 | "bigInt": 9.223372036854776e+58 4 | } -------------------------------------------------------------------------------- /assets/pass5_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | bigDouble: 92233720368547758073829419051489548484843823585675828488686.0 3 | bigInt: 92233720368547758073829419051489548484843823585675828488686 4 | } 5 | -------------------------------------------------------------------------------- /assets/pass6_result.hjson: -------------------------------------------------------------------------------- 1 | { 2 | a: 1 3 | b: 2 4 | c: 3 5 | d: 4 6 | e: 5 7 | f: 6 8 | } -------------------------------------------------------------------------------- /assets/pass6_result.json: -------------------------------------------------------------------------------- 1 | { 2 | "a": 1, 3 | "b": 2, 4 | "c": 3, 5 | "d": 4, 6 | "e": 5, 7 | "f": 6 8 | } -------------------------------------------------------------------------------- /assets/pass6_test.hjson: -------------------------------------------------------------------------------- 1 | a: 1, b: 2,c:3,'d' /*cm1*/ : 4, /*cm2 */ e: /* cm3*/ 5 /* cm 4 */ f : 6 2 | -------------------------------------------------------------------------------- /assets/passSingle_result.hjson: -------------------------------------------------------------------------------- 1 | allow quoteless strings -------------------------------------------------------------------------------- /assets/passSingle_result.json: -------------------------------------------------------------------------------- 1 | "allow quoteless strings" -------------------------------------------------------------------------------- /assets/passSingle_test.hjson: -------------------------------------------------------------------------------- 1 | allow quoteless strings -------------------------------------------------------------------------------- /assets/root_result.hjson: -------------------------------------------------------------------------------- 1 | { 2 | database: 3 | { 4 | host: 127.0.0.1 5 | port: 555 6 | } 7 | } -------------------------------------------------------------------------------- /assets/root_result.json: -------------------------------------------------------------------------------- 1 | { 2 | "database": { 3 | "host": "127.0.0.1", 4 | "port": 555 5 | } 6 | } -------------------------------------------------------------------------------- /assets/root_test.hjson: -------------------------------------------------------------------------------- 1 | // a object with the root braces omitted 2 | database: 3 | { 4 | host: 127.0.0.1 5 | port: 555 6 | } 7 | -------------------------------------------------------------------------------- /assets/stringify1_result.hjson: -------------------------------------------------------------------------------- 1 | { 2 | quotes: 3 | { 4 | num1: "1,2" 5 | num2: "-1.1 ," 6 | num3: "1e10 ,2" 7 | num4: "-1e-10," 8 | kw1: "true," 9 | kw2: "false ," 10 | kw3: "null,123" 11 | close1: "1}" 12 | close1b: "1 }" 13 | close2: "1]" 14 | close2b: "1 ]" 15 | close3: "1," 16 | close3b: "1 ," 17 | comment1: "1#str" 18 | comment2: "1//str" 19 | comment3: "1/*str*/" 20 | punc1: "{" 21 | punc1b: "{foo" 22 | punc2: "}" 23 | punc2b: "}foo" 24 | punc3: "[" 25 | punc3b: "[foo" 26 | punc4: "]" 27 | punc4b: "]foo" 28 | punc5: "," 29 | punc5b: ",foo" 30 | punc6: ":" 31 | punc6b: ":foo" 32 | } 33 | noquotes: 34 | { 35 | num0: .1,2 36 | num1: 1.1.1,2 37 | num2: -.1, 38 | num3: 1e10e,2 39 | num4: -1e--10, 40 | kw1: true1, 41 | kw2: false0, 42 | kw3: null0, 43 | close1: a} 44 | close2: a] 45 | comment1: a#str 46 | comment2: a//str 47 | comment3: a/*str*/ 48 | } 49 | } -------------------------------------------------------------------------------- /assets/stringify1_result.json: -------------------------------------------------------------------------------- 1 | { 2 | "quotes": { 3 | "num1": "1,2", 4 | "num2": "-1.1 ,", 5 | "num3": "1e10 ,2", 6 | "num4": "-1e-10,", 7 | "kw1": "true,", 8 | "kw2": "false ,", 9 | "kw3": "null,123", 10 | "close1": "1}", 11 | "close1b": "1 }", 12 | "close2": "1]", 13 | "close2b": "1 ]", 14 | "close3": "1,", 15 | "close3b": "1 ,", 16 | "comment1": "1#str", 17 | "comment2": "1//str", 18 | "comment3": "1/*str*/", 19 | "punc1": "{", 20 | "punc1b": "{foo", 21 | "punc2": "}", 22 | "punc2b": "}foo", 23 | "punc3": "[", 24 | "punc3b": "[foo", 25 | "punc4": "]", 26 | "punc4b": "]foo", 27 | "punc5": ",", 28 | "punc5b": ",foo", 29 | "punc6": ":", 30 | "punc6b": ":foo" 31 | }, 32 | "noquotes": { 33 | "num0": ".1,2", 34 | "num1": "1.1.1,2", 35 | "num2": "-.1,", 36 | "num3": "1e10e,2", 37 | "num4": "-1e--10,", 38 | "kw1": "true1,", 39 | "kw2": "false0,", 40 | "kw3": "null0,", 41 | "close1": "a}", 42 | "close2": "a]", 43 | "comment1": "a#str", 44 | "comment2": "a//str", 45 | "comment3": "a/*str*/" 46 | } 47 | } -------------------------------------------------------------------------------- /assets/stringify1_test.hjson: -------------------------------------------------------------------------------- 1 | // test if stringify produces correct output 2 | { 3 | quotes: 4 | { 5 | num1: "1,2" 6 | num2: "-1.1 ," 7 | num3: "1e10 ,2" 8 | num4: "-1e-10," 9 | kw1: "true," 10 | kw2: "false ," 11 | kw3: "null,123" 12 | close1: "1}" 13 | close1b: "1 }" 14 | close2: "1]" 15 | close2b: "1 ]" 16 | close3: "1," 17 | close3b: "1 ," 18 | comment1: "1#str" 19 | comment2: "1//str" 20 | comment3: "1/*str*/" 21 | punc1: "{" 22 | punc1b: "{foo" 23 | punc2: "}" 24 | punc2b: "}foo" 25 | punc3: "[" 26 | punc3b: "[foo" 27 | punc4: "]" 28 | punc4b: "]foo" 29 | punc5: "," 30 | punc5b: ",foo" 31 | punc6: ":" 32 | punc6b: ":foo" 33 | } 34 | noquotes: 35 | { 36 | num0: ".1,2" 37 | num1: "1.1.1,2" 38 | num2: "-.1," 39 | num3: "1e10e,2" 40 | num4: "-1e--10," 41 | kw1: "true1," 42 | kw2: "false0," 43 | kw3: "null0," 44 | close1: "a}" 45 | close2: "a]" 46 | comment1: "a#str" 47 | comment2: "a//str" 48 | comment3: "a/*str*/" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /assets/strings2_result.hjson: -------------------------------------------------------------------------------- 1 | { 2 | key1: a key in single quotes 3 | "key 2": a key in single quotes 4 | "key \"": a key in single quotes 5 | text: 6 | [ 7 | single quoted string 8 | '''You need quotes for escapes''' 9 | " untrimmed " 10 | "untrimmed " 11 | containing " double quotes 12 | containing " double quotes 13 | containing " double quotes 14 | '''"containing more " double quotes"''' 15 | containing ' single quotes 16 | containing ' single quotes 17 | containing ' single quotes 18 | "'containing more ' single quotes'" 19 | "'containing more ' single quotes'" 20 | "\n" 21 | " \n" 22 | "\n \n \n \n" 23 | "\t\n" 24 | ] 25 | foo3a: asdf''' 26 | foo3b: "'''asdf" 27 | foo4a: "asdf'''\nasdf" 28 | foo4b: "asdf\n'''asdf" 29 | } -------------------------------------------------------------------------------- /assets/strings2_result.json: -------------------------------------------------------------------------------- 1 | { 2 | "key1": "a key in single quotes", 3 | "key 2": "a key in single quotes", 4 | "key \"": "a key in single quotes", 5 | "text": [ 6 | "single quoted string", 7 | "You need quotes\tfor escapes", 8 | " untrimmed ", 9 | "untrimmed ", 10 | "containing \" double quotes", 11 | "containing \" double quotes", 12 | "containing \" double quotes", 13 | "\"containing more \" double quotes\"", 14 | "containing ' single quotes", 15 | "containing ' single quotes", 16 | "containing ' single quotes", 17 | "'containing more ' single quotes'", 18 | "'containing more ' single quotes'", 19 | "\n", 20 | " \n", 21 | "\n \n \n \n", 22 | "\t\n" 23 | ], 24 | "foo3a": "asdf'''", 25 | "foo3b": "'''asdf", 26 | "foo4a": "asdf'''\nasdf", 27 | "foo4b": "asdf\n'''asdf" 28 | } -------------------------------------------------------------------------------- /assets/strings2_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # Hjson 3 allows the use of single quotes 3 | 4 | 'key1': a key in single quotes 5 | 'key 2': a key in single quotes 6 | 'key "': a key in single quotes 7 | 8 | text: [ 9 | 'single quoted string' 10 | 'You need quotes\tfor escapes' 11 | ' untrimmed ' 12 | 'untrimmed ' 13 | 'containing " double quotes' 14 | 'containing \" double quotes' 15 | "containing \" double quotes" 16 | '"containing more " double quotes"' 17 | 'containing \' single quotes' 18 | "containing ' single quotes" 19 | "containing \' single quotes" 20 | "'containing more ' single quotes'" 21 | "\'containing more \' single quotes\'" 22 | 23 | '\n' 24 | ' \n' 25 | '\n \n \n \n' 26 | '\t\n' 27 | ] 28 | 29 | # escapes/no escape 30 | 31 | foo3a: 'asdf\'\'\'' 32 | foo3b: '\'\'\'asdf' 33 | 34 | foo4a: 'asdf\'\'\'\nasdf' 35 | foo4b: 'asdf\n\'\'\'asdf' 36 | } 37 | -------------------------------------------------------------------------------- /assets/strings_result.hjson: -------------------------------------------------------------------------------- 1 | { 2 | text1: This is a valid string value. 3 | text2: a \ is just a \ 4 | text3: '''You need quotes for escapes''' 5 | text4a: " untrimmed " 6 | text4b: " untrimmed" 7 | text4c: "untrimmed " 8 | notml1: "\n" 9 | notml2: " \n" 10 | notml3: "\n \n \n \n" 11 | notml4: "\t\n" 12 | multiline1: 13 | ''' 14 | first line 15 | indented line 16 | last line 17 | ''' 18 | multiline2: 19 | ''' 20 | first line 21 | indented line 22 | last line 23 | ''' 24 | multiline3: 25 | ''' 26 | first line 27 | indented line 28 | last line 29 | 30 | ''' 31 | foo1a: asdf\"'a\s\w 32 | foo1b: asdf\"'a\s\w 33 | foo1c: asdf\"'a\s\w 34 | foo2a: '''"asdf"''' 35 | foo2b: '''"asdf"''' 36 | foo3a: asdf''' 37 | foo3b: "'''asdf" 38 | foo4a: "asdf'''\nasdf" 39 | foo4b: "asdf\n'''asdf" 40 | arr: 41 | [ 42 | one 43 | two 44 | three 45 | four 46 | ] 47 | not: 48 | { 49 | number: 5 50 | negative: -4.2 51 | yes: true 52 | no: false 53 | null: null 54 | array: 55 | [ 56 | 1 57 | 2 58 | 3 59 | 4 60 | 5 61 | 6 62 | 7 63 | 8 64 | 9 65 | 0 66 | -1 67 | 0.5 68 | ] 69 | } 70 | special: 71 | { 72 | true: "true" 73 | false: "false" 74 | null: "null" 75 | one: "1" 76 | two: "2" 77 | minus: "-3" 78 | } 79 | } -------------------------------------------------------------------------------- /assets/strings_result.json: -------------------------------------------------------------------------------- 1 | { 2 | "text1": "This is a valid string value.", 3 | "text2": "a \\ is just a \\", 4 | "text3": "You need quotes\tfor escapes", 5 | "text4a": " untrimmed ", 6 | "text4b": " untrimmed", 7 | "text4c": "untrimmed ", 8 | "notml1": "\n", 9 | "notml2": " \n", 10 | "notml3": "\n \n \n \n", 11 | "notml4": "\t\n", 12 | "multiline1": "first line\n indented line\nlast line", 13 | "multiline2": "first line\n indented line\nlast line", 14 | "multiline3": "first line\n indented line\nlast line\n", 15 | "foo1a": "asdf\\\"'a\\s\\w", 16 | "foo1b": "asdf\\\"'a\\s\\w", 17 | "foo1c": "asdf\\\"'a\\s\\w", 18 | "foo2a": "\"asdf\"", 19 | "foo2b": "\"asdf\"", 20 | "foo3a": "asdf'''", 21 | "foo3b": "'''asdf", 22 | "foo4a": "asdf'''\nasdf", 23 | "foo4b": "asdf\n'''asdf", 24 | "arr": [ 25 | "one", 26 | "two", 27 | "three", 28 | "four" 29 | ], 30 | "not": { 31 | "number": 5, 32 | "negative": -4.2, 33 | "yes": true, 34 | "no": false, 35 | "null": null, 36 | "array": [ 37 | 1, 38 | 2, 39 | 3, 40 | 4, 41 | 5, 42 | 6, 43 | 7, 44 | 8, 45 | 9, 46 | 0, 47 | -1, 48 | 0.5 49 | ] 50 | }, 51 | "special": { 52 | "true": "true", 53 | "false": "false", 54 | "null": "null", 55 | "one": "1", 56 | "two": "2", 57 | "minus": "-3" 58 | } 59 | } -------------------------------------------------------------------------------- /assets/strings_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | # simple 3 | 4 | text1: This is a valid string value. 5 | text2:a \ is just a \ 6 | 7 | text3: "You need quotes\tfor escapes" 8 | 9 | text4a: " untrimmed " 10 | text4b: " untrimmed" 11 | text4c: "untrimmed " 12 | 13 | notml1: "\n" 14 | notml2: " \n" 15 | notml3: "\n \n \n \n" 16 | notml4: "\t\n" 17 | 18 | # multiline string 19 | 20 | multiline1: 21 | ''' 22 | first line 23 | indented line 24 | last line 25 | ''' 26 | 27 | multiline2: 28 | '''first line 29 | indented line 30 | last line''' 31 | 32 | multiline3: 33 | ''' 34 | first line 35 | indented line 36 | last line 37 | 38 | ''' # trailing lf 39 | 40 | # escapes/no escape 41 | 42 | foo1a: asdf\"'a\s\w 43 | foo1b: '''asdf\"'a\s\w''' 44 | foo1c: "asdf\\\"'a\\s\\w" 45 | 46 | foo2a: "\"asdf\"" 47 | foo2b: '''"asdf"''' 48 | 49 | foo3a: "asdf'''" 50 | foo3b: "'''asdf" 51 | 52 | foo4a: "asdf'''\nasdf" 53 | foo4b: "asdf\n'''asdf" 54 | 55 | # in arrays 56 | arr: 57 | [ 58 | one 59 | two 60 | "three" 61 | '''four''' 62 | ] 63 | 64 | # not strings 65 | not: 66 | { 67 | number: 5 68 | negative: -4.2 69 | yes: true 70 | no: false 71 | null: null 72 | array: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, -1, 0.5 ] 73 | } 74 | 75 | # special quoted 76 | special: 77 | { 78 | true: "true" 79 | false: "false" 80 | null: "null" 81 | one: "1" 82 | two: "2" 83 | minus: "-3" 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /assets/testlist.txt: -------------------------------------------------------------------------------- 1 | charset2_test.hjson 2 | charset_test.hjson 3 | comments_test.hjson 4 | comments2_test.hjson 5 | comments3_test.hjson 6 | comments4_test.hjson 7 | comments5_test.hjson 8 | comments6_test.hjson 9 | comments7_test.hjson 10 | empty_test.hjson 11 | failCharset1_test.hjson 12 | failJSON02_test.json 13 | failJSON05_test.json 14 | failJSON06_test.json 15 | failJSON07_test.json 16 | failJSON08_test.json 17 | failJSON10_test.json 18 | failJSON11_test.json 19 | failJSON12_test.json 20 | failJSON13_test.json 21 | failJSON14_test.json 22 | failJSON15_test.json 23 | failJSON16_test.json 24 | failJSON17_test.json 25 | failJSON19_test.json 26 | failJSON20_test.json 27 | failJSON21_test.json 28 | failJSON22_test.json 29 | failJSON23_test.json 30 | failJSON26_test.json 31 | failJSON28_test.json 32 | failJSON29_test.json 33 | failJSON30_test.json 34 | failJSON31_test.json 35 | failJSON32_test.json 36 | failJSON33_test.json 37 | failJSON34_test.json 38 | failKey1_test.hjson 39 | failKey2_test.hjson 40 | failKey3_test.hjson 41 | failKey4_test.hjson 42 | failKey5_test.hjson 43 | failMLStr1_test.hjson 44 | failObj1_test.hjson 45 | failObj2_test.hjson 46 | failObj3_test.hjson 47 | failStr1a_test.hjson 48 | failStr1b_test.hjson 49 | failStr1c_test.hjson 50 | failStr1d_test.hjson 51 | failStr2a_test.hjson 52 | failStr2b_test.hjson 53 | failStr2c_test.hjson 54 | failStr2d_test.hjson 55 | failStr3a_test.hjson 56 | failStr3b_test.hjson 57 | failStr3c_test.hjson 58 | failStr3d_test.hjson 59 | failStr4a_test.hjson 60 | failStr4b_test.hjson 61 | failStr4c_test.hjson 62 | failStr4d_test.hjson 63 | failStr5a_test.hjson 64 | failStr5b_test.hjson 65 | failStr5c_test.hjson 66 | failStr5d_test.hjson 67 | failStr6a_test.hjson 68 | failStr6b_test.hjson 69 | failStr6c_test.hjson 70 | failStr6d_test.hjson 71 | failStr7a_test.hjson 72 | failStr8a_test.hjson 73 | kan_test.hjson 74 | keys_test.hjson 75 | mltabs_test.json 76 | oa_test.hjson 77 | pass1_test.json 78 | pass2_test.json 79 | pass3_test.json 80 | pass4_test.json 81 | pass5_test.hjson 82 | pass6_test.hjson 83 | passSingle_test.hjson 84 | root_test.hjson 85 | stringify1_test.hjson 86 | strings2_test.hjson 87 | strings_test.hjson 88 | trail_test.hjson 89 | stringify/quotes_all_test.hjson 90 | stringify/quotes_always_test.hjson 91 | stringify/quotes_keys_test.hjson 92 | stringify/quotes_strings_ml_test.json 93 | stringify/quotes_strings_test.hjson 94 | extra/notabs_test.json 95 | extra/root_test.hjson 96 | extra/separator_test.json 97 | -------------------------------------------------------------------------------- /assets/trail_result.hjson: -------------------------------------------------------------------------------- 1 | { 2 | foo: 0 -- this string starts at 0 and ends at 1, preceding and trailing whitespace is ignored -- 1 3 | } -------------------------------------------------------------------------------- /assets/trail_result.json: -------------------------------------------------------------------------------- 1 | { 2 | "foo": "0 -- this string starts at 0 and ends at 1, preceding and trailing whitespace is ignored -- 1" 3 | } -------------------------------------------------------------------------------- /assets/trail_test.hjson: -------------------------------------------------------------------------------- 1 | { 2 | // the following line contains trailing whitespace: 3 | foo: 0 -- this string starts at 0 and ends at 1, preceding and trailing whitespace is ignored -- 1 4 | } 5 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'maven-publish' 4 | id 'signing' 5 | } 6 | 7 | java { 8 | sourceCompatibility = JavaVersion.VERSION_1_8 9 | targetCompatibility = JavaVersion.VERSION_1_8 10 | } 11 | 12 | sourceSets { 13 | main { 14 | java { 15 | srcDir 'src/main' 16 | } 17 | } 18 | test { 19 | java { 20 | srcDir 'src/test' 21 | } 22 | resources { 23 | srcDir 'assets' 24 | } 25 | } 26 | } 27 | 28 | task javadocJar(type: Jar, dependsOn: javadoc) { 29 | archiveClassifier = 'javadoc' 30 | from 'build/docs/javadoc' 31 | } 32 | 33 | task sourcesJar(type: Jar, dependsOn: classes) { 34 | archiveClassifier = 'sources' 35 | from sourceSets.main.allSource 36 | } 37 | 38 | jar { 39 | manifest { 40 | attributes( 41 | 'Hjson-Version': project.version, 42 | ) 43 | } 44 | } 45 | 46 | artifacts { 47 | archives jar 48 | archives sourcesJar 49 | archives javadocJar 50 | } 51 | 52 | task(testSuite, dependsOn: ['classes','testClasses'], type: JavaExec) { 53 | mainClass = 'org.hjson.test.Main' 54 | classpath = files(sourceSets.main.runtimeClasspath, sourceSets.test.runtimeClasspath) 55 | } 56 | 57 | test.dependsOn testSuite 58 | 59 | publishing { 60 | publications { 61 | maven(MavenPublication) { 62 | from components.java 63 | artifact sourcesJar 64 | artifact javadocJar 65 | pom { 66 | name = "Hjson Library" 67 | description = project.description 68 | url = "https://github.com/hjson/hjson-java" 69 | licenses { 70 | license { 71 | name = "The MIT License (MIT)" 72 | url = "https://github.com/hjson/hjson-java/blob/master/LICENSE" 73 | distribution = "repo" 74 | } 75 | } 76 | developers { 77 | developer { 78 | id = "laktak" 79 | name = "Christian Zangl" 80 | } 81 | developer { 82 | id = "trobro" 83 | name = "Fredrik Trobro" 84 | } 85 | } 86 | scm { 87 | connection = "scm:git@github.com:hjson/hjson-java.git" 88 | developerConnection = "scm:git@github.com:hjson/hjson-java.git" 89 | url = "https://github.com/hjson/hjson-java" 90 | } 91 | } 92 | } 93 | } 94 | repositories { 95 | maven { 96 | name = "OSSRH" 97 | url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" 98 | credentials { 99 | username = System.getenv("MAVEN_USERNAME") 100 | password = System.getenv("MAVEN_PASSWORD") 101 | } 102 | } 103 | } 104 | } 105 | 106 | signing { 107 | def signingKey = System.getenv("GPG_SIGNING_KEY") 108 | def signingPassword = System.getenv("GPG_SIGNING_PASSWORD") 109 | useInMemoryPgpKeys(signingKey, signingPassword) 110 | sign publishing.publications.maven 111 | } 112 | -------------------------------------------------------------------------------- /cli/bin/hjson: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | SELF=`dirname $0` 3 | java -jar $SELF/Hjson-cli.jar $* 4 | -------------------------------------------------------------------------------- /cli/bin/hjson.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | java -jar %~dp0\Hjson-cli.jar %* 3 | -------------------------------------------------------------------------------- /cli/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'maven' 3 | apply plugin: 'application' 4 | 5 | version = '3.0.0' 6 | group = 'org.hjson.cli' 7 | description = """Hjson CLI""" 8 | 9 | sourceCompatibility = 1.8 10 | targetCompatibility = 1.8 11 | 12 | sourceSets { 13 | main { 14 | java { 15 | srcDir 'src' 16 | } 17 | } 18 | } 19 | 20 | repositories { 21 | flatDir { 22 | dirs '../build/libs' 23 | } 24 | mavenCentral() 25 | } 26 | 27 | dependencies { 28 | compile 'org.hjson:hjson:'+version 29 | compile 'commons-cli:commons-cli:1.3.1' 30 | } 31 | 32 | mainClassName = 'org.hjson.cli.Main' 33 | 34 | jar { 35 | baseName = 'Hjson' 36 | manifest { 37 | attributes( 38 | 'Class-Path': configurations.compile.collect { it.getName() }.join(' '), 39 | 'Main-Class': 'org.hjson.cli.Main', 40 | 'Hjson-Version': version, 41 | ) 42 | } 43 | } 44 | 45 | task distjar(type: Jar) { 46 | manifest=jar.manifest 47 | archiveName="Hjson-cli.jar" 48 | //baseName="Hjson-dist" 49 | from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } 50 | with jar 51 | 52 | } 53 | 54 | task dist(type: Copy, dependsOn: distjar) { 55 | from('build/libs') { 56 | include '*.jar' 57 | } 58 | from('bin') { 59 | include '*' 60 | } 61 | into 'build/target' 62 | } 63 | 64 | task zip(type:Zip, dependsOn: dist) { 65 | from ('build/target') 66 | include '*' 67 | archiveName 'hjson.zip' 68 | destinationDir file('build/zip') 69 | } 70 | -------------------------------------------------------------------------------- /cli/src/org.hjson.cli/Main.java: -------------------------------------------------------------------------------- 1 | package org.hjson.cli; 2 | 3 | import org.hjson.*; 4 | import java.io.*; 5 | import static java.lang.System.out; 6 | import org.apache.commons.cli.*; 7 | 8 | import java.lang.reflect.*; 9 | import java.util.jar.Manifest; 10 | import java.util.jar.Attributes; 11 | import java.util.List; 12 | import java.util.ArrayList; 13 | import java.net.URL; 14 | 15 | public class Main { 16 | 17 | public static String convertStreamToString(InputStream is) throws IOException { 18 | Writer writer=new StringWriter(); 19 | char[] buffer=new char[1024]; 20 | try { 21 | Reader reader=new BufferedReader(new InputStreamReader(is, "UTF-8")); 22 | int n; 23 | while ((n=reader.read(buffer))!=-1) writer.write(buffer, 0, n); 24 | } finally { 25 | is.close(); 26 | } 27 | return writer.toString(); 28 | } 29 | 30 | public static void main(String[] args) throws Exception { 31 | 32 | Options options=new Options(); 33 | options.addOption(Option.builder("h").longOpt("help").desc("Show this screen").build()); 34 | options.addOption(Option.builder("j").desc("Output as formatted JSON").build()); 35 | options.addOption(Option.builder("c").desc("Output as JSON").build()); 36 | options.addOption(Option.builder("v").longOpt("version").desc("Show version").build()); 37 | options.addOption(Option.builder().longOpt("math").desc("Enable math DSF (experimental)").build()); 38 | options.addOption(Option.builder().longOpt("hex").desc("Enable hex DSF (experimental)").build()); 39 | 40 | HjsonOptions opt=new HjsonOptions(); 41 | 42 | CommandLineParser parser=new DefaultParser(); 43 | HelpFormatter formatter=new HelpFormatter(); 44 | CommandLine cmd; 45 | 46 | try { 47 | cmd=parser.parse(options, args); 48 | 49 | List dsf=new ArrayList(); 50 | 51 | if (cmd.hasOption("hex")) dsf.add(HjsonDsf.hex(false)); 52 | if (cmd.hasOption("math")) dsf.add(HjsonDsf.math()); 53 | opt.setDsfProviders(dsf.toArray(new IHjsonDsfProvider[0])); 54 | 55 | if (cmd.hasOption("h")) { 56 | formatter.printHelp("hjson [INPUT]", options); 57 | return; 58 | } else if (cmd.hasOption("v")) { 59 | String className=JsonObject.class.getSimpleName()+".class"; 60 | String classPath=JsonObject.class.getResource(className).toString(); 61 | if (!classPath.startsWith("jar")) return; 62 | String manifestPath=classPath.substring(0, classPath.lastIndexOf("!")+1)+"/META-INF/MANIFEST.MF"; 63 | Attributes attr=new Manifest(new URL(manifestPath).openStream()).getMainAttributes(); 64 | out.println("hjson v"+attr.getValue("Hjson-Version")); 65 | return; 66 | } 67 | 68 | List cargs=cmd.getArgList(); 69 | Reader reader; 70 | 71 | if (cargs.size()>1) throw new org.apache.commons.cli.ParseException("input"); 72 | 73 | if (cargs.isEmpty()) reader=new InputStreamReader(System.in); 74 | else reader=new FileReader(cargs.get(0)); 75 | JsonValue value=JsonValue.readHjson(reader, opt); 76 | 77 | if (cmd.hasOption("j")) out.println(value.toString(Stringify.FORMATTED)); 78 | else if (cmd.hasOption("c")) out.println(value.toString(Stringify.PLAIN)); 79 | else out.println(value.toString(opt)); 80 | 81 | } catch (org.apache.commons.cli.ParseException e) { 82 | out.println(e.getMessage()); 83 | formatter.printHelp("hjson [INPUT]", options); 84 | System.exit(1); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | package-list 2 | -------------------------------------------------------------------------------- /docs/allclasses-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | All Classes (hjson 3.1.0 API) 7 | 8 | 9 | 10 | 11 |

All Classes

12 |
13 | 25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /docs/allclasses-noframe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | All Classes (hjson 3.1.0 API) 7 | 8 | 9 | 10 | 11 |

All Classes

12 |
13 | 25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /docs/constant-values.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Constant Field Values (hjson 3.1.0 API) 7 | 8 | 9 | 10 | 11 | 21 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 | 32 | 40 |
41 | 68 | 69 |
70 |

Constant Field Values

71 |

Contents

72 |
73 | 74 |
75 | 76 | 77 | 78 | 79 | 80 | 81 | 89 |
90 | 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /docs/deprecated-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Deprecated List (hjson 3.1.0 API) 7 | 8 | 9 | 10 | 11 | 21 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 | 32 | 40 |
41 | 68 | 69 |
70 |

Deprecated API

71 |

Contents

72 | 75 |
76 |
77 | 78 | 79 | 101 |
102 | 103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 118 |
119 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /docs/help-doc.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | API Help (hjson 3.1.0 API) 7 | 8 | 9 | 10 | 11 | 21 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 | 32 | 40 |
41 | 68 | 69 |
70 |

How This API Document Is Organized

71 |
This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.
72 |
73 |
74 |
    75 |
  • 76 |

    Package

    77 |

    Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain six categories:

    78 |
      79 |
    • Interfaces (italic)
    • 80 |
    • Classes
    • 81 |
    • Enums
    • 82 |
    • Exceptions
    • 83 |
    • Errors
    • 84 |
    • Annotation Types
    • 85 |
    86 |
  • 87 |
  • 88 |

    Class/Interface

    89 |

    Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:

    90 |
      91 |
    • Class inheritance diagram
    • 92 |
    • Direct Subclasses
    • 93 |
    • All Known Subinterfaces
    • 94 |
    • All Known Implementing Classes
    • 95 |
    • Class/interface declaration
    • 96 |
    • Class/interface description
    • 97 |
    98 |
      99 |
    • Nested Class Summary
    • 100 |
    • Field Summary
    • 101 |
    • Constructor Summary
    • 102 |
    • Method Summary
    • 103 |
    104 |
      105 |
    • Field Detail
    • 106 |
    • Constructor Detail
    • 107 |
    • Method Detail
    • 108 |
    109 |

    Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.

    110 |
  • 111 |
  • 112 |

    Annotation Type

    113 |

    Each annotation type has its own separate page with the following sections:

    114 |
      115 |
    • Annotation Type declaration
    • 116 |
    • Annotation Type description
    • 117 |
    • Required Element Summary
    • 118 |
    • Optional Element Summary
    • 119 |
    • Element Detail
    • 120 |
    121 |
  • 122 |
  • 123 |

    Enum

    124 |

    Each enum has its own separate page with the following sections:

    125 |
      126 |
    • Enum declaration
    • 127 |
    • Enum description
    • 128 |
    • Enum Constant Summary
    • 129 |
    • Enum Constant Detail
    • 130 |
    131 |
  • 132 |
  • 133 |

    Tree (Class Hierarchy)

    134 |

    There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object.

    135 |
      136 |
    • When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
    • 137 |
    • When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
    • 138 |
    139 |
  • 140 |
  • 141 |

    Deprecated API

    142 |

    The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.

    143 |
  • 144 |
  • 145 |

    Index

    146 |

    The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.

    147 |
  • 148 |
  • 149 |

    Prev/Next

    150 |

    These links take you to the next or previous class, interface, package, or related page.

    151 |
  • 152 |
  • 153 |

    Frames/No Frames

    154 |

    These links show and hide the HTML frames. All pages are available with or without frames.

    155 |
  • 156 |
  • 157 |

    All Classes

    158 |

    The All Classes link shows all classes and interfaces except non-static nested types.

    159 |
  • 160 |
  • 161 |

    Serialized Form

    162 |

    Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description.

    163 |
  • 164 |
  • 165 |

    Constant Field Values

    166 |

    The Constant Field Values page lists the static final fields and their values.

    167 |
  • 168 |
169 | This help file applies to API documentation generated using the standard doclet.
170 | 171 |
172 | 173 | 174 | 175 | 176 | 177 | 178 | 186 |
187 | 214 | 215 | 216 | 217 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | hjson 3.1.0 API 7 | 60 | 61 | 62 | 63 | 64 | 65 | <noscript> 66 | <div>JavaScript is disabled on your browser.</div> 67 | </noscript> 68 | <h2>Frame Alert</h2> 69 | <p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to <a href="org/hjson/package-summary.html">Non-frame version</a>.</p> 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /docs/org/hjson/HjsonDsf.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | HjsonDsf (hjson 3.1.0 API) 7 | 8 | 9 | 10 | 11 | 27 | 30 | 31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 46 |
47 | 89 | 90 | 91 |
92 |
org.hjson
93 |

Class HjsonDsf

94 |
95 |
96 |
    97 |
  • java.lang.Object
  • 98 |
  • 99 |
      100 |
    • org.hjson.HjsonDsf
    • 101 |
    102 |
  • 103 |
104 |
105 |
    106 |
  • 107 |
    108 |
    109 |
    public class HjsonDsf
    110 | extends java.lang.Object
    111 |
    Provides standard DSF providers.
    112 |
  • 113 |
114 |
115 |
116 |
    117 |
  • 118 | 119 |
      120 |
    • 121 | 122 | 123 |

      Method Summary

      124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 135 | 136 | 137 | 138 | 141 | 142 |
      All Methods Static Methods Concrete Methods 
      Modifier and TypeMethod and Description
      static IHjsonDsfProviderhex(boolean stringify) 133 |
      Returns a hex DSF provider
      134 |
      static IHjsonDsfProvidermath() 139 |
      Returns a math DSF provider
      140 |
      143 |
        144 |
      • 145 | 146 | 147 |

        Methods inherited from class java.lang.Object

        148 | clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • 149 |
      150 |
    • 151 |
    152 |
  • 153 |
154 |
155 |
156 |
    157 |
  • 158 | 159 |
      160 |
    • 161 | 162 | 163 |

      Method Detail

      164 | 165 | 166 | 167 |
        168 |
      • 169 |

        math

        170 |
        public static IHjsonDsfProvider math()
        171 |
        Returns a math DSF provider
        172 |
        173 |
        Returns:
        174 |
        DSF provider
        175 |
        176 |
      • 177 |
      178 | 179 | 180 | 181 |
        182 |
      • 183 |

        hex

        184 |
        public static IHjsonDsfProvider hex(boolean stringify)
        185 |
        Returns a hex DSF provider
        186 |
        187 |
        Parameters:
        188 |
        stringify - true to output all integers as hex values
        189 |
        Returns:
        190 |
        DSF provider
        191 |
        192 |
      • 193 |
      194 |
    • 195 |
    196 |
  • 197 |
198 |
199 |
200 | 201 | 202 |
203 | 204 | 205 | 206 | 207 | 208 | 209 | 217 |
218 | 260 | 261 | 262 | 263 | -------------------------------------------------------------------------------- /docs/org/hjson/IHjsonDsfProvider.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | IHjsonDsfProvider (hjson 3.1.0 API) 7 | 8 | 9 | 10 | 11 | 27 | 30 | 31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 46 |
47 | 89 | 90 | 91 |
92 |
org.hjson
93 |

Interface IHjsonDsfProvider

94 |
95 |
96 |
97 |
    98 |
  • 99 |
    100 |
    101 |
    public interface IHjsonDsfProvider
    102 |
    A interface to support Domain Specific Formats for Hjson.
    103 |
  • 104 |
105 |
106 |
107 |
    108 |
  • 109 | 110 |
      111 |
    • 112 | 113 | 114 |

      Method Summary

      115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 126 | 127 | 128 | 129 | 132 | 133 | 134 | 135 | 138 | 139 | 140 | 141 | 144 | 145 |
      All Methods Instance Methods Abstract Methods 
      Modifier and TypeMethod and Description
      java.lang.StringgetDescription() 124 |
      Gets the description of this DSF.
      125 |
      java.lang.StringgetName() 130 |
      Gets the name of this DSF.
      131 |
      JsonValueparse(java.lang.String text) 136 |
      Tries to parse the text as a DSF value.
      137 |
      java.lang.Stringstringify(JsonValue value) 142 |
      Stringifies DSF values.
      143 |
      146 |
    • 147 |
    148 |
  • 149 |
150 |
151 |
152 |
    153 |
  • 154 | 155 |
      156 |
    • 157 | 158 | 159 |

      Method Detail

      160 | 161 | 162 | 163 |
        164 |
      • 165 |

        getName

        166 |
        java.lang.String getName()
        167 |
        Gets the name of this DSF.
        168 |
        169 |
        Returns:
        170 |
        name
        171 |
        172 |
      • 173 |
      174 | 175 | 176 | 177 |
        178 |
      • 179 |

        getDescription

        180 |
        java.lang.String getDescription()
        181 |
        Gets the description of this DSF.
        182 |
        183 |
        Returns:
        184 |
        description
        185 |
        186 |
      • 187 |
      188 | 189 | 190 | 191 |
        192 |
      • 193 |

        parse

        194 |
        JsonValue parse(java.lang.String text)
        195 |
        Tries to parse the text as a DSF value.
        196 |
        197 |
        Parameters:
        198 |
        text - the DSF value
        199 |
        Returns:
        200 |
        JsonValue
        201 |
        202 |
      • 203 |
      204 | 205 | 206 | 207 |
        208 |
      • 209 |

        stringify

        210 |
        java.lang.String stringify(JsonValue value)
        211 |
        Stringifies DSF values.
        212 |
        213 |
        Parameters:
        214 |
        value - the JSON value
        215 |
        Returns:
        216 |
        string
        217 |
        218 |
      • 219 |
      220 |
    • 221 |
    222 |
  • 223 |
224 |
225 |
226 | 227 | 228 |
229 | 230 | 231 | 232 | 233 | 234 | 235 | 243 |
244 | 286 | 287 | 288 | 289 | -------------------------------------------------------------------------------- /docs/org/hjson/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | org.hjson (hjson 3.1.0 API) 7 | 8 | 9 | 10 | 11 |

org.hjson

12 |
13 |

Interfaces

14 | 17 |

Classes

18 | 26 |

Enums

27 | 31 |

Exceptions

32 | 35 |
36 | 37 | 38 | -------------------------------------------------------------------------------- /docs/org/hjson/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | org.hjson (hjson 3.1.0 API) 7 | 8 | 9 | 10 | 11 | 21 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 | 32 | 40 |
41 | 68 | 69 |
70 |

Package org.hjson

71 |
72 |
73 |
    74 |
  • 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 87 | 88 | 89 |
    Interface Summary 
    InterfaceDescription
    IHjsonDsfProvider 85 |
    A interface to support Domain Specific Formats for Hjson.
    86 |
    90 |
  • 91 |
  • 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 104 | 105 | 106 | 107 | 110 | 111 | 112 | 113 | 116 | 117 | 118 | 119 | 123 | 124 | 125 | 126 | 129 | 130 | 131 | 132 | 135 | 136 | 137 |
    Class Summary 
    ClassDescription
    HjsonDsf 102 |
    Provides standard DSF providers.
    103 |
    HjsonOptions 108 |
    Defines options for Hjson
    109 |
    JsonArray 114 |
    Represents a JSON array, an ordered collection of JSON values.
    115 |
    JsonObject 120 |
    Represents a JSON object, a set of name/value pairs, where the names are strings and the values 121 | are JSON values.
    122 |
    JsonObject.Member 127 |
    Represents a member of a JSON object, a pair of a name and a value.
    128 |
    JsonValue 133 |
    Represents a JSON value.
    134 |
    138 |
  • 139 |
  • 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 152 | 153 | 154 | 155 | 158 | 159 | 160 |
    Enum Summary 
    EnumDescription
    JsonType 150 |
    Defines the known json types.
    151 |
    Stringify 156 |
    The ToString format.
    157 |
    161 |
  • 162 |
  • 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 175 | 176 | 177 |
    Exception Summary 
    ExceptionDescription
    ParseException 173 |
    An unchecked exception to indicate that an input does not qualify as valid JSON.
    174 |
    178 |
  • 179 |
180 |
181 | 182 |
183 | 184 | 185 | 186 | 187 | 188 | 189 | 197 |
198 | 225 | 226 | 227 | 228 | -------------------------------------------------------------------------------- /docs/org/hjson/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | org.hjson Class Hierarchy (hjson 3.1.0 API) 7 | 8 | 9 | 10 | 11 | 21 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 | 32 | 40 |
41 | 68 | 69 |
70 |

Hierarchy For Package org.hjson

71 |
72 |
73 |

Class Hierarchy

74 |
    75 |
  • java.lang.Object 76 |
      77 |
    • org.hjson.HjsonDsf
    • 78 |
    • org.hjson.HjsonOptions
    • 79 |
    • org.hjson.JsonObject.Member
    • 80 |
    • org.hjson.JsonValue (implements java.io.Serializable) 81 |
        82 |
      • org.hjson.JsonArray (implements java.lang.Iterable<T>)
      • 83 |
      • org.hjson.JsonObject (implements java.lang.Iterable<T>)
      • 84 |
      85 |
    • 86 |
    • java.lang.Throwable (implements java.io.Serializable) 87 |
        88 |
      • java.lang.Exception 89 |
          90 |
        • java.lang.RuntimeException 91 | 94 |
        • 95 |
        96 |
      • 97 |
      98 |
    • 99 |
    100 |
  • 101 |
102 |

Interface Hierarchy

103 | 106 |

Enum Hierarchy

107 |
    108 |
  • java.lang.Object 109 |
      110 |
    • java.lang.Enum<E> (implements java.lang.Comparable<T>, java.io.Serializable) 111 | 115 |
    • 116 |
    117 |
  • 118 |
119 |
120 | 121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 136 |
137 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /docs/overview-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Class Hierarchy (hjson 3.1.0 API) 7 | 8 | 9 | 10 | 11 | 21 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 | 32 | 40 |
41 | 68 | 69 |
70 |

Hierarchy For All Packages

71 | Package Hierarchies: 72 | 75 |
76 |
77 |

Class Hierarchy

78 |
    79 |
  • java.lang.Object 80 |
      81 |
    • org.hjson.HjsonDsf
    • 82 |
    • org.hjson.HjsonOptions
    • 83 |
    • org.hjson.JsonObject.Member
    • 84 |
    • org.hjson.JsonValue (implements java.io.Serializable) 85 |
        86 |
      • org.hjson.JsonArray (implements java.lang.Iterable<T>)
      • 87 |
      • org.hjson.JsonObject (implements java.lang.Iterable<T>)
      • 88 |
      89 |
    • 90 |
    • java.lang.Throwable (implements java.io.Serializable) 91 |
        92 |
      • java.lang.Exception 93 |
          94 |
        • java.lang.RuntimeException 95 | 98 |
        • 99 |
        100 |
      • 101 |
      102 |
    • 103 |
    104 |
  • 105 |
106 |

Interface Hierarchy

107 | 110 |

Enum Hierarchy

111 |
    112 |
  • java.lang.Object 113 |
      114 |
    • java.lang.Enum<E> (implements java.lang.Comparable<T>, java.io.Serializable) 115 | 119 |
    • 120 |
    121 |
  • 122 |
123 |
124 | 125 |
126 | 127 | 128 | 129 | 130 | 131 | 132 | 140 |
141 | 168 | 169 | 170 | 171 | -------------------------------------------------------------------------------- /docs/script.js: -------------------------------------------------------------------------------- 1 | function show(type) 2 | { 3 | count = 0; 4 | for (var key in methods) { 5 | var row = document.getElementById(key); 6 | if ((methods[key] & type) != 0) { 7 | row.style.display = ''; 8 | row.className = (count++ % 2) ? rowColor : altColor; 9 | } 10 | else 11 | row.style.display = 'none'; 12 | } 13 | updateTabs(type); 14 | } 15 | 16 | function updateTabs(type) 17 | { 18 | for (var value in tabs) { 19 | var sNode = document.getElementById(tabs[value][0]); 20 | var spanNode = sNode.firstChild; 21 | if (value == type) { 22 | sNode.className = activeTableTab; 23 | spanNode.innerHTML = tabs[value][1]; 24 | } 25 | else { 26 | sNode.className = tableTab; 27 | spanNode.innerHTML = "" + tabs[value][1] + ""; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /docs/serialized-form.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Serialized Form (hjson 3.1.0 API) 7 | 8 | 9 | 10 | 11 | 21 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 | 32 | 40 |
41 | 68 | 69 |
70 |

Serialized Form

71 |
72 |
73 |
    74 |
  • 75 |

    Package org.hjson

    76 |
      77 |
    • 78 | 79 | 80 |

      Class org.hjson.JsonArray extends JsonValue implements Serializable

      81 |
        82 |
      • 83 |

        Serialized Fields

        84 |
          85 |
        • 86 |

          values

          87 |
          java.util.List<E> values
          88 |
        • 89 |
        90 |
      • 91 |
      92 |
    • 93 |
    • 94 | 95 | 96 |

      Class org.hjson.JsonObject extends JsonValue implements Serializable

      97 |
        98 |
      • 99 |

        Serialization Methods

        100 |
          101 |
        • 102 |

          readObject

          103 |
          private void readObject(java.io.ObjectInputStream inputStream)
          104 |                  throws java.io.IOException,
          105 |                         java.lang.ClassNotFoundException
          106 |
          107 |
          Throws:
          108 |
          java.io.IOException
          109 |
          java.lang.ClassNotFoundException
          110 |
          111 |
        • 112 |
        113 |
      • 114 |
      • 115 |

        Serialized Fields

        116 |
          117 |
        • 118 |

          names

          119 |
          java.util.List<E> names
          120 |
        • 121 |
        • 122 |

          values

          123 |
          java.util.List<E> values
          124 |
        • 125 |
        126 |
      • 127 |
      128 |
    • 129 |
    • 130 | 131 | 132 |

      Class org.hjson.JsonValue extends java.lang.Object implements Serializable

      133 |
    • 134 |
    • 135 | 136 | 137 |

      Class org.hjson.ParseException extends java.lang.RuntimeException implements Serializable

      138 |
        139 |
      • 140 |

        Serialized Fields

        141 |
          142 |
        • 143 |

          offset

          144 |
          int offset
          145 |
        • 146 |
        • 147 |

          line

          148 |
          int line
          149 |
        • 150 |
        • 151 |

          column

          152 |
          int column
          153 |
        • 154 |
        155 |
      • 156 |
      157 |
    • 158 |
    159 |
  • 160 |
161 |
162 | 163 |
164 | 165 | 166 | 167 | 168 | 169 | 170 | 178 |
179 | 206 | 207 | 208 | 209 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | group=org.hjson 2 | name=hjson 3 | version=3.1.0 4 | description=Hjson, the Human JSON 5 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjson/hjson-java/88e93c05704a5c241277dd4357b4baf337d1a914/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /history.md: -------------------------------------------------------------------------------- 1 | # hjson-java History 2 | 3 | - v3.1.0 4 | - escapes all control chars 5 | - changes in formatted JSON output: 6 | - opening braces now appear on the same line as the key when an array or an object are values in an object 7 | - the root object or array are no longer preceded by a blank newline 8 | - empty arrays or objects now appear on a line of their own when they are elements in an array 9 | - v3.0.1 10 | - fix for CVE-2023-34620 by not trying to parse more than 1000 levels into arrays and/or objects 11 | - fix for empty multiline string inside array or object 12 | - v3.0.0 13 | - add support for single quoted strings 14 | - add option to turn off legacy support for omitting root braces 15 | - HjsonWriter will always emit root braces 16 | - v2.1.1 17 | - Update ML stringify to match JS 18 | - v2.1.0 19 | - add DSF (domain specific formats), experimental 20 | - v2.0.5 21 | - fix stringify for strings staring with a punctuator char 22 | - v2.0.1 23 | - move to hjson org 24 | - v2.0.0 25 | - fix quoteless string starting with punctuator 26 | - add cli 27 | - v1.1.4 28 | - fix writer for comment tokens in keyname 29 | - v1.1.3 30 | - fix trailing whitespace in keyname 31 | - v1.1.2 32 | - fix trailing space in quoteless strings 33 | - v1.1.1 34 | - better error messages & root check 35 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'hjson' 2 | -------------------------------------------------------------------------------- /src/main/org/hjson/HjsonDsf.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2016 Christian Zangl 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | ******************************************************************************/ 22 | package org.hjson; 23 | 24 | import java.util.*; 25 | import java.util.regex.Matcher; 26 | import java.util.regex.Pattern; 27 | 28 | /** 29 | * Provides standard DSF providers. 30 | */ 31 | public class HjsonDsf 32 | { 33 | private HjsonDsf() {} 34 | 35 | /** 36 | * Returns a math DSF provider 37 | * @return DSF provider 38 | */ 39 | public static IHjsonDsfProvider math() { return new DsfMath(); } 40 | /** 41 | * Returns a hex DSF provider 42 | * 43 | * @param stringify true to output all integers as hex values 44 | * @return DSF provider 45 | */ 46 | public static IHjsonDsfProvider hex(boolean stringify) { return new DsfHex(stringify); } 47 | // /** 48 | // * Returns a date DSF provider. 49 | // * @return DSF provider 50 | // */ 51 | // public static IHjsonDsfProvider date() { return new DsfDate(); } 52 | 53 | static boolean isInvalidDsfChar(char c) 54 | { 55 | return c == '{' || c == '}' || c == '[' || c == ']' || c == ','; 56 | } 57 | 58 | static JsonValue parse(IHjsonDsfProvider[] dsfProviders, String value) 59 | { 60 | for (int i=0, n=dsfProviders.length; itrue if this feature is enabled. 55 | */ 56 | public boolean getParseLegacyRoot() { return legacyRoot; } 57 | 58 | /** 59 | * Sets whether root braces should be emitted. 60 | * 61 | * @param value value 62 | */ 63 | public void setParseLegacyRoot(boolean value) { legacyRoot=value; } 64 | 65 | /** 66 | * Detects whether root braces should be emitted. 67 | * 68 | * @deprecated will always return true. 69 | * @return true if this feature is enabled. 70 | */ 71 | @Deprecated 72 | public boolean getEmitRootBraces() { return true; } 73 | 74 | /** 75 | * Sets whether root braces should be emitted. 76 | * 77 | * @deprecated root braces are always emitted. 78 | * @param value value 79 | */ 80 | @Deprecated 81 | public void setEmitRootBraces(boolean value) { } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/main/org/hjson/HjsonWriter.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2017 Christian Zangl 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | ******************************************************************************/ 22 | package org.hjson; 23 | 24 | import java.io.IOException; 25 | import java.io.Writer; 26 | import java.util.regex.Matcher; 27 | import java.util.regex.Pattern; 28 | 29 | class HjsonWriter { 30 | 31 | private IHjsonDsfProvider[] dsfProviders; 32 | 33 | static String commonRange = "\\x7f-\\x9f\\x{00ad}\\x{0600}-\\x{0604}\\x{070f}\\x{17b4}\\x{17b5}\\x{200c}-\\x{200f}\\x{2028}-\\x{202f}\\x{2060}-\\x{206f}\\x{feff}\\x{fff0}-\\x{ffff}"; 34 | // needsEscape tests if the string can be written without escapes 35 | static Pattern needsEscape = Pattern.compile("[\\\\\\\"\\x00-\\x1f" + commonRange + "]"); 36 | // needsQuotes tests if the string can be written as a quoteless string (includes needsEscape but without \\\\ and \\") 37 | static Pattern needsQuotes = Pattern.compile("^\\s|^\"|^'|^#|^/\\*|^//|^\\{|^\\}|^\\[|^\\]|^:|^,|\\s$|[\\x00-\\x1f\\x7f-\\x9f\\x{00ad}\\x{0600}-\\x{0604}\\x{070f}\\x{17b4}\\x{17b5}\\x{200c}-\\x{200f}\\x{2028}-\\x{202f}\\x{2060}-\\x{206f}\\x{feff}\\x{fff0}-\\x{ffff}]"); 38 | // needsEscapeML tests if the string can be written as a multiline string (like needsEscape but without \\n, \\\\, \\", \\t) 39 | static Pattern needsEscapeML = Pattern.compile("'''|^[\\s]+$|[\\x00-\\x08\\x0b-\\x1f" + commonRange + "]"); 40 | static Pattern needsEscapeName=Pattern.compile("[,\\{\\[\\}\\]\\s:#\"']|//|/\\*"); 41 | 42 | public HjsonWriter(HjsonOptions options) { 43 | if (options!=null) { 44 | dsfProviders=options.getDsfProviders(); 45 | } else { 46 | dsfProviders=new IHjsonDsfProvider[0]; 47 | } 48 | } 49 | 50 | void nl(Writer tw, int level) throws IOException { 51 | tw.write(JsonValue.eol); 52 | for (int i=0; i0) nl(tw, level); else tw.write(separator); } 75 | tw.write('{'); 76 | 77 | for (JsonObject.Member pair : obj) { 78 | nl(tw, level+1); 79 | tw.write(escapeName(pair.getName())); 80 | tw.write(":"); 81 | save(pair.getValue(), tw, level+1, " ", false); 82 | } 83 | 84 | if (obj.size()>0) nl(tw, level); 85 | tw.write('}'); 86 | break; 87 | case ARRAY: 88 | JsonArray arr=value.asArray(); 89 | int n=arr.size(); 90 | if (!noIndent) { if (n>0) nl(tw, level); else tw.write(separator); } 91 | tw.write('['); 92 | for (int i=0; i0) nl(tw, level); 97 | tw.write(']'); 98 | break; 99 | case BOOLEAN: 100 | tw.write(separator); 101 | tw.write(value.isTrue()?"true":"false"); 102 | break; 103 | case STRING: 104 | writeString(value.asString(), tw, level, separator); 105 | break; 106 | default: 107 | tw.write(separator); 108 | tw.write(value.toString()); 109 | break; 110 | } 111 | } 112 | 113 | static String escapeName(String name) { 114 | if (name.length()==0 || needsEscapeName.matcher(name).find() || 115 | needsEscape.matcher(name).find()) 116 | { 117 | return "\""+JsonWriter.escapeString(name)+"\""; 118 | } else { 119 | return name; 120 | } 121 | } 122 | 123 | void writeString(String value, Writer tw, int level, String separator) throws IOException { 124 | if (value.length()==0) { tw.write(separator+"\"\""); return; } 125 | 126 | char left=value.charAt(0), right=value.charAt(value.length()-1); 127 | char left1=value.length()>1?value.charAt(1):'\0', left2=value.length()>2?value.charAt(2):'\0'; 128 | boolean doEscape=needsQuotes.matcher(value).find(); 129 | 130 | if (doEscape || 131 | HjsonParser.isWhiteSpace(left) || HjsonParser.isWhiteSpace(right) || 132 | left=='"' || 133 | left=='\'' || 134 | left=='#' || 135 | left=='/' && (left1=='*' || left1=='/') || 136 | JsonValue.isPunctuatorChar(left) || 137 | HjsonParser.tryParseNumber(value, true)!=null || 138 | startsWithKeyword(value)) { 139 | // If the String contains no control characters, no quote characters, and no 140 | // backslash characters, then we can safely slap some quotes around it. 141 | // Otherwise we first check if the String can be expressed in multiline 142 | // format or we must replace the offending characters with safe escape 143 | // sequences. 144 | 145 | if (!needsEscape.matcher(value).find()) { 146 | tw.write(separator+"\""+value+"\""); 147 | } else if (!needsEscapeML.matcher(value).find()) { 148 | writeMLString(value, tw, level, separator); 149 | } else { 150 | tw.write(separator+"\""+JsonWriter.escapeString(value)+"\""); 151 | } 152 | } 153 | else tw.write(separator+value); 154 | } 155 | 156 | void writeMLString(String value, Writer tw, int level, String separator) throws IOException { 157 | String[] lines=value.replace("\r", "").split("\n", -1); 158 | 159 | if (lines.length==1) { 160 | tw.write(separator+"'''"); 161 | tw.write(lines[0]); 162 | tw.write("'''"); 163 | } 164 | else { 165 | level++; 166 | nl(tw, level); 167 | tw.write("'''"); 168 | 169 | for (String line : lines) { 170 | nl(tw, line.length()>0?level:0); 171 | tw.write(line); 172 | } 173 | nl(tw, level); 174 | tw.write("'''"); 175 | } 176 | } 177 | 178 | static boolean startsWithKeyword(String text) { 179 | int p; 180 | if (text.startsWith("true") || text.startsWith("null")) p=4; 181 | else if (text.startsWith("false")) p=5; 182 | else return false; 183 | while (pp+1 && (text.charAt(p+1)=='/' || text.charAt(p+1)=='*')); 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /src/main/org/hjson/IHjsonDsfProvider.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2016 Christian Zangl 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | ******************************************************************************/ 22 | package org.hjson; 23 | 24 | /** 25 | * A interface to support Domain Specific Formats for Hjson. 26 | */ 27 | public interface IHjsonDsfProvider 28 | { 29 | /** 30 | * Gets the name of this DSF. 31 | * 32 | * @return name 33 | */ 34 | public String getName(); 35 | /** 36 | * Gets the description of this DSF. 37 | * 38 | * @return description 39 | */ 40 | public String getDescription(); 41 | /** 42 | * Tries to parse the text as a DSF value. 43 | * 44 | * @param text the DSF value 45 | * @return JsonValue 46 | */ 47 | public JsonValue parse(String text); 48 | /** 49 | * Stringifies DSF values. 50 | * 51 | * @param value the JSON value 52 | * @return string 53 | */ 54 | public String stringify(JsonValue value); 55 | } 56 | -------------------------------------------------------------------------------- /src/main/org/hjson/JsonDsf.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2016 Christian Zangl 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | ******************************************************************************/ 22 | package org.hjson; 23 | 24 | @SuppressWarnings("serial") // use default serial UID 25 | class JsonDsf extends JsonValue { 26 | 27 | private final Object value; 28 | 29 | JsonDsf(Object value) { 30 | this.value=value; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "null"; 36 | } 37 | 38 | @Override 39 | public JsonType getType() { 40 | return JsonType.DSF; 41 | } 42 | 43 | @Override 44 | public Object asDsf() { 45 | return value; 46 | } 47 | 48 | @Override 49 | public int hashCode() { 50 | return value.hashCode(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/org/hjson/JsonLiteral.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013, 2015 EclipseSource. 3 | * Copyright (c) 2015-2016 Christian Zangl 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | ******************************************************************************/ 23 | package org.hjson; 24 | 25 | import java.io.IOException; 26 | 27 | 28 | @SuppressWarnings("serial") // use default serial UID 29 | class JsonLiteral extends JsonValue { 30 | 31 | enum Iv { T, F, N }; 32 | 33 | static final JsonValue NULL=new JsonLiteral(Iv.N); 34 | static final JsonValue TRUE=new JsonLiteral(Iv.T); 35 | static final JsonValue FALSE=new JsonLiteral(Iv.F); 36 | 37 | private final Iv value; 38 | 39 | private JsonLiteral(Iv value) { 40 | this.value=value; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | switch (value) { 46 | case T: return "true"; 47 | case F: return "false"; 48 | case N: return "null"; 49 | default: return null; 50 | } 51 | } 52 | 53 | @Override 54 | public int hashCode() { 55 | return value.hashCode(); 56 | } 57 | 58 | @Override 59 | public JsonType getType() { 60 | return value==Iv.N ? JsonType.NULL : JsonType.BOOLEAN; 61 | } 62 | 63 | @Override 64 | public boolean isNull() { 65 | return value==Iv.N; 66 | } 67 | 68 | @Override 69 | public boolean isTrue() { 70 | return value==Iv.T; 71 | } 72 | 73 | @Override 74 | public boolean isFalse() { 75 | return value==Iv.F; 76 | } 77 | 78 | @Override 79 | public boolean isBoolean() { 80 | return value!=Iv.N; 81 | } 82 | 83 | @Override 84 | public boolean asBoolean() { 85 | return value==Iv.N ? super.asBoolean() : value==Iv.T; 86 | } 87 | 88 | @Override 89 | public boolean equals(Object object) { 90 | if (this==object) { 91 | return true; 92 | } 93 | if (object==null) { 94 | return false; 95 | } 96 | if (getClass()!=object.getClass()) { 97 | return false; 98 | } 99 | JsonLiteral other=(JsonLiteral)object; 100 | return value==other.value; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/main/org/hjson/JsonNumber.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013, 2015 EclipseSource. 3 | * Copyright (c) 2015-2016 Christian Zangl 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | ******************************************************************************/ 23 | package org.hjson; 24 | 25 | import java.io.IOException; 26 | import java.math.BigDecimal; 27 | 28 | 29 | @SuppressWarnings("serial") // use default serial UID 30 | class JsonNumber extends JsonValue { 31 | 32 | private final double value; 33 | 34 | JsonNumber(double value) { 35 | this.value=value; 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | long l=(long)value; 41 | if (l==value) return Long.toString(l); 42 | String res=BigDecimal.valueOf(value).toEngineeringString(); 43 | if (res.endsWith(".0")) return res.substring(0, res.length()-2); 44 | else if (res.contains("E")) { 45 | res=Double.toString(value); 46 | res=res.replace("E-", "e-").replace("E", "e+"); 47 | } 48 | return res; 49 | } 50 | 51 | @Override 52 | public JsonType getType() { 53 | return JsonType.NUMBER; 54 | } 55 | 56 | @Override 57 | public boolean isNumber() { 58 | return true; 59 | } 60 | 61 | @Override 62 | public int asInt() { 63 | return (int)value; 64 | } 65 | 66 | @Override 67 | public long asLong() { 68 | return (long)value; 69 | } 70 | 71 | @Override 72 | public float asFloat() { 73 | return (float)value; 74 | } 75 | 76 | @Override 77 | public double asDouble() { 78 | return value; 79 | } 80 | 81 | @Override 82 | public int hashCode() { 83 | return Double.valueOf(value).hashCode(); 84 | } 85 | 86 | @Override 87 | public boolean equals(Object object) { 88 | if (this==object) { 89 | return true; 90 | } 91 | if (object==null) { 92 | return false; 93 | } 94 | if (getClass()!=object.getClass()) { 95 | return false; 96 | } 97 | JsonNumber other=(JsonNumber)object; 98 | return value==other.value; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/main/org/hjson/JsonString.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013, 2015 EclipseSource. 3 | * Copyright (c) 2015-2016 Christian Zangl 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | ******************************************************************************/ 23 | package org.hjson; 24 | 25 | import java.io.IOException; 26 | 27 | 28 | @SuppressWarnings("serial") // use default serial UID 29 | class JsonString extends JsonValue { 30 | 31 | private final String string; 32 | 33 | JsonString(String string) { 34 | if (string==null) { 35 | throw new NullPointerException("string is null"); 36 | } 37 | this.string=string; 38 | } 39 | 40 | @Override 41 | public JsonType getType() { 42 | return JsonType.STRING; 43 | } 44 | 45 | @Override 46 | public boolean isString() { 47 | return true; 48 | } 49 | 50 | @Override 51 | public String asString() { 52 | return string; 53 | } 54 | 55 | @Override 56 | public int hashCode() { 57 | return string.hashCode(); 58 | } 59 | 60 | @Override 61 | public boolean equals(Object object) { 62 | if (this==object) { 63 | return true; 64 | } 65 | if (object==null) { 66 | return false; 67 | } 68 | if (getClass()!=object.getClass()) { 69 | return false; 70 | } 71 | JsonString other=(JsonString)object; 72 | return string.equals(other.string); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/org/hjson/JsonType.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2016 Christian Zangl 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | ******************************************************************************/ 22 | package org.hjson; 23 | 24 | /** 25 | * Defines the known json types. 26 | * There is no null type as the primitive will be null instead of the JsonValue containing null. 27 | */ 28 | public enum JsonType 29 | { 30 | /** 31 | * Json value of type string. 32 | */ 33 | STRING, 34 | /** 35 | * Json value of type number. 36 | */ 37 | NUMBER, 38 | /** 39 | * Json value of type object. 40 | */ 41 | OBJECT, 42 | /** 43 | * Json value of type array. 44 | */ 45 | ARRAY, 46 | /** 47 | * Json value of type boolean. 48 | */ 49 | BOOLEAN, 50 | /** 51 | * Json value of type null. 52 | */ 53 | NULL, 54 | /** 55 | * Json value of type DSF. 56 | */ 57 | DSF, 58 | } 59 | -------------------------------------------------------------------------------- /src/main/org/hjson/JsonWriter.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013, 2015 EclipseSource. 3 | * Copyright (c) 2015-2016 Christian Zangl 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | ******************************************************************************/ 23 | package org.hjson; 24 | 25 | import java.io.IOException; 26 | import java.io.Writer; 27 | import java.util.regex.Matcher; 28 | 29 | 30 | class JsonWriter { 31 | 32 | boolean format; 33 | 34 | public JsonWriter(boolean format) { 35 | this.format=format; 36 | } 37 | 38 | void nl(Writer tw, int level) throws IOException { 39 | if (format) { 40 | tw.write(JsonValue.eol); 41 | for (int i=0; i 0) tw.write(","); 73 | JsonValue v=arr.get(i); 74 | nl(tw, level+1); 75 | save(arr.get(i), tw, level+1); 76 | } 77 | if (n > 0) nl(tw, level); 78 | tw.write(']'); 79 | break; 80 | case BOOLEAN: 81 | tw.write(value.isTrue()?"true":"false"); 82 | break; 83 | case STRING: 84 | tw.write('"'); 85 | tw.write(escapeString(value.asString())); 86 | tw.write('"'); 87 | break; 88 | default: 89 | tw.write(value.toString()); 90 | break; 91 | } 92 | } 93 | 94 | static String escapeString(String src) { 95 | if (src==null) return null; 96 | 97 | int i = 0; 98 | StringBuilder sb=new StringBuilder(); 99 | Matcher m = HjsonWriter.needsEscape.matcher(src); 100 | 101 | while (m.find()) { 102 | // Assume all matches are single chars. 103 | sb.append(src, i, m.start()).append(getEscapedChar(m.group().charAt(0))); 104 | i = m.end(); 105 | } 106 | 107 | if (i < 1) { 108 | return src; 109 | } 110 | 111 | sb.append(src, i, src.length()); 112 | 113 | return sb.toString(); 114 | } 115 | 116 | private static String getEscapedChar(char c) { 117 | switch (c) { 118 | case '\"': return "\\\""; 119 | case '\t': return "\\t"; 120 | case '\n': return "\\n"; 121 | case '\r': return "\\r"; 122 | case '\f': return "\\f"; 123 | case '\b': return "\\b"; 124 | case '\\': return "\\\\"; 125 | default: return "\\u" + String.format("%04x", (int) c); 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/main/org/hjson/ParseException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013, 2014 EclipseSource. 3 | * Copyright (c) 2015-2016 Christian Zangl 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | ******************************************************************************/ 23 | package org.hjson; 24 | 25 | 26 | /** 27 | * An unchecked exception to indicate that an input does not qualify as valid JSON. 28 | */ 29 | @SuppressWarnings("serial") // use default serial UID 30 | public class ParseException extends RuntimeException { 31 | 32 | private final int offset; 33 | private final int line; 34 | private final int column; 35 | 36 | ParseException(String message, int offset, int line, int column) { 37 | super(message+" at "+line+":"+column); 38 | this.offset=offset; 39 | this.line=line; 40 | this.column=column; 41 | } 42 | 43 | /** 44 | * Returns the absolute index of the character at which the error occurred. The 45 | * index of the first character of a document is 0. 46 | * 47 | * @return the character offset at which the error occurred, will be >= 0 48 | */ 49 | public int getOffset() { 50 | return offset; 51 | } 52 | 53 | /** 54 | * Returns the number of the line in which the error occurred. The first line counts as 1. 55 | * 56 | * @return the line in which the error occurred, will be >= 1 57 | */ 58 | public int getLine() { 59 | return line; 60 | } 61 | 62 | /** 63 | * Returns the index of the character at which the error occurred, relative to the line. The 64 | * index of the first character of a line is 0. 65 | * 66 | * @return the column in which the error occurred, will be >= 0 67 | */ 68 | public int getColumn() { 69 | return column; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/org/hjson/Stringify.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2016 Christian Zangl 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | ******************************************************************************/ 22 | package org.hjson; 23 | 24 | /** The ToString format. */ 25 | public enum Stringify { 26 | /** JSON (no whitespace). */ 27 | PLAIN, 28 | /** Formatted JSON. */ 29 | FORMATTED, 30 | /** Hjson. */ 31 | HJSON, 32 | } 33 | 34 | -------------------------------------------------------------------------------- /src/main/org/hjson/WritingBuffer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 EclipseSource. 3 | * Copyright (c) 2015-2016 Christian Zangl 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | ******************************************************************************/ 23 | package org.hjson; 24 | 25 | import java.io.IOException; 26 | import java.io.Writer; 27 | 28 | 29 | /** 30 | * A lightweight writing buffer to reduce the amount of write operations to be performed on the 31 | * underlying writer. This implementation is not thread-safe. It deliberately deviates from the 32 | * contract of Writer. In particular, it does not flush or close the wrapped writer nor does it 33 | * ensure that the wrapped writer is open. 34 | */ 35 | class WritingBuffer extends Writer { 36 | 37 | private final Writer writer; 38 | private final char[] buffer; 39 | private int fill=0; 40 | 41 | WritingBuffer(Writer writer) { 42 | this(writer, 16); 43 | } 44 | 45 | WritingBuffer(Writer writer, int bufferSize) { 46 | this.writer=writer; 47 | buffer=new char[bufferSize]; 48 | } 49 | 50 | @Override 51 | public void write(int c) throws IOException { 52 | if (fill>buffer.length-1) { 53 | flush(); 54 | } 55 | buffer[fill++]=(char)c; 56 | } 57 | 58 | @Override 59 | public void write(char[] cbuf, int off, int len) throws IOException { 60 | if (fill>buffer.length-len) { 61 | flush(); 62 | if (len>buffer.length) { 63 | writer.write(cbuf, off, len); 64 | return; 65 | } 66 | } 67 | System.arraycopy(cbuf, off, buffer, fill, len); 68 | fill += len; 69 | } 70 | 71 | @Override 72 | public void write(String str, int off, int len) throws IOException { 73 | if (fill>buffer.length-len) { 74 | flush(); 75 | if (len>buffer.length) { 76 | writer.write(str, off, len); 77 | return; 78 | } 79 | } 80 | str.getChars(off, off+len, buffer, fill); 81 | fill += len; 82 | } 83 | 84 | /** 85 | * Flushes the internal buffer but does not flush the wrapped writer. 86 | */ 87 | @Override 88 | public void flush() throws IOException { 89 | writer.write(buffer, 0, fill); 90 | fill=0; 91 | } 92 | 93 | /** 94 | * Does not close or flush the wrapped writer. 95 | */ 96 | @Override 97 | public void close() throws IOException { 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/test/org/hjson/test/Main.java: -------------------------------------------------------------------------------- 1 | package org.hjson.test; 2 | 3 | import org.hjson.*; 4 | import java.io.*; 5 | import static java.lang.System.out; 6 | 7 | public class Main { 8 | 9 | public static String convertStreamToString(InputStream is) throws IOException { 10 | Writer writer=new StringWriter(); 11 | char[] buffer=new char[1024]; 12 | try { 13 | Reader reader=new BufferedReader(new InputStreamReader(is, "UTF-8")); 14 | int n; 15 | while ((n=reader.read(buffer))!=-1) writer.write(buffer, 0, n); 16 | } finally { 17 | is.close(); 18 | } 19 | return writer.toString(); 20 | } 21 | 22 | private static String load(String file, boolean cr) throws Exception { 23 | InputStream res=Main.class.getResourceAsStream("/"+file); 24 | if (res==null) throw new Exception(file+" not found!"); 25 | String text=convertStreamToString(res); 26 | String std=text.replace("\r", ""); // make sure we have unix style text regardless of the input 27 | return cr ? std.replace("\n", "\r\n") : std; 28 | } 29 | 30 | private static boolean test(String name, String file, boolean inputCr, boolean outputCr) throws Exception { 31 | boolean shouldFail=name.startsWith("fail"); 32 | 33 | JsonValue.setEol(outputCr?"\r\n":"\n"); 34 | String text=load(file, inputCr); 35 | 36 | try { 37 | JsonValue data=JsonValue.readHjson(text); 38 | String data1=data.toString(Stringify.FORMATTED); 39 | String hjson1=data.toString(Stringify.HJSON); 40 | if (!shouldFail) { 41 | String json2 = load(name+"_result.json", outputCr); 42 | JsonValue result=JsonValue.readJSON(json2); 43 | String data2=result.toString(Stringify.FORMATTED); 44 | String hjson2=load(name+"_result.hjson", outputCr); 45 | if (!data1.equals(data2)) return failErr(name, "parse", data1, data2); 46 | if (!hjson1.equals(hjson2)) return failErr(name, "stringify", hjson1, hjson2); 47 | if (!data1.equals(json2)) return failErr(name, "JSON stringify", data1, json2); 48 | } 49 | else return failErr(name, "should fail", null, null); 50 | } 51 | catch (Exception e) { 52 | if (!shouldFail) return failErr(name, "exception", e.toString(), ""); 53 | } 54 | return true; 55 | } 56 | 57 | static boolean failErr(String name, String type, String s1, String s2) { 58 | out.println(name+" "+type+" FAILED!"); 59 | if (s1!=null || s2!=null) { 60 | out.printf("--- actual (%d):\n", s1.length()); 61 | out.println(s1+"---"); 62 | out.printf("--- expected (%d):\n", s2.length()); 63 | out.println(s2+"---"); 64 | if (s1.length()==s2.length()) 65 | for (int i=0; i