How to transform string with objects and array indexes into json

Ivan

I receive from another program Map with string representation of elements:

Map<String,String> properties = new HashMap<String,String>() {{
    put("news[0].title", "Title 1");
    put("news[0].body",  "Body 1");
    put("news[1].title", "Title 2");
    put("news[1].body",  "Body 2");
}};

I need to render it into freemarker-template. In question

freemarker-flat-structure-of-passing-parameters-transfer-to-array-of-objects

we decided that it is impossible to parse this kind of values in freemarker. But freemarker can eval json.

So I need to know how to transform this map into objects or json. I need something like that:

{
    "news": [
        {"title": "Title1", "body": "Body1"},
        {"title": "Title2", "body": "Body2"}            
    ]
}

Names of parameters in map are unknown, not exactly "news", not exactly "title" and "body", I don't know. May be there are some libraries for such purposes?

ddekany

Since you are using your own language there, just write a parser for it. It's not a complex language after all. Also, transforming it to JSON doesn't make sense, based on what I know about the problem. Yes, the FTL expression syntax and JSON syntax overlaps quite much. But you shouldn't parse anything inside the FTL-s, just parse your language to List-s and JavaBeans and/or Map-s, and pass that plain Java object to FreeMarker.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Transform JSON objects to an new array

From Dev

How to transform flat JavaScript objects array into nested hierarchical JSON structure?

From Dev

How to convert array to json string in javascript having indexes inside the element

From Dev

Javascript how to transform an array of objects

From Dev

How to transform an object into an array of objects?

From Dev

Encode array to JSON string without array indexes

From Dev

How to change a JSON string to an array of objects?

From Dev

Make JQ transform an array of objects to a string

From Dev

How to transform array into array of objects by Lodash

From Dev

How to transform a JSON string to NSArray

From Dev

Array of String to an array of JSON objects

From Dev

How to transform my array of objects to get this output?

From Dev

How to correctly transform JSON into Python objects?

From Dev

How to transform JSON objects into TS class

From Dev

How to transform Array[(String,List[String])] to Array[(String,String)]

From Dev

how to know the indexes of the smallest 15 objects inside an NSMutable array and store these indexes in another array

From Dev

How to create a JSON array as string from groovy objects?

From Dev

How does CLR deal with accesses to array indexes of fields of objects

From Dev

Transform array of objects in Ruby

From Dev

Transform array of objects into an object

From Dev

Aggregate and transform array of objects

From Dev

Transform structure of array of objects

From Dev

Transform structure of array of objects

From Dev

How to transform string to array in angularjs's html

From Dev

PlayFramework: how to transform each element of a JSON array

From Dev

java - replace string in JSON with json array of objects

From Java

How to find multiple indexes in array of objects by the value of an object property that nests in a property of array of objects?

From Dev

How to convert JSON to list string, when some of the JSON objects are string and some are array?

From Dev

How to transform an object into an array of objects without using jQuery?

Related Related

  1. 1

    Transform JSON objects to an new array

  2. 2

    How to transform flat JavaScript objects array into nested hierarchical JSON structure?

  3. 3

    How to convert array to json string in javascript having indexes inside the element

  4. 4

    Javascript how to transform an array of objects

  5. 5

    How to transform an object into an array of objects?

  6. 6

    Encode array to JSON string without array indexes

  7. 7

    How to change a JSON string to an array of objects?

  8. 8

    Make JQ transform an array of objects to a string

  9. 9

    How to transform array into array of objects by Lodash

  10. 10

    How to transform a JSON string to NSArray

  11. 11

    Array of String to an array of JSON objects

  12. 12

    How to transform my array of objects to get this output?

  13. 13

    How to correctly transform JSON into Python objects?

  14. 14

    How to transform JSON objects into TS class

  15. 15

    How to transform Array[(String,List[String])] to Array[(String,String)]

  16. 16

    how to know the indexes of the smallest 15 objects inside an NSMutable array and store these indexes in another array

  17. 17

    How to create a JSON array as string from groovy objects?

  18. 18

    How does CLR deal with accesses to array indexes of fields of objects

  19. 19

    Transform array of objects in Ruby

  20. 20

    Transform array of objects into an object

  21. 21

    Aggregate and transform array of objects

  22. 22

    Transform structure of array of objects

  23. 23

    Transform structure of array of objects

  24. 24

    How to transform string to array in angularjs's html

  25. 25

    PlayFramework: how to transform each element of a JSON array

  26. 26

    java - replace string in JSON with json array of objects

  27. 27

    How to find multiple indexes in array of objects by the value of an object property that nests in a property of array of objects?

  28. 28

    How to convert JSON to list string, when some of the JSON objects are string and some are array?

  29. 29

    How to transform an object into an array of objects without using jQuery?

HotTag

Archive