简体   繁体   中英

How to ignore the underlying structure of a JSON property and store it as a string?

I have a JSON file like this:

{
    "Resources": {
        "HelloWorldFunction": {
            "Type": "AWS::Serverless::Function",
            "Properties": {
                "Handler": "index.handler",
                "Runtime": "nodejs8.10",
                "Events": {
                    "HelloWorldApi": {
                        "Type": "Api",
                        "Properties": {
                            "Path": "/",
                            "Method": "GET"
                        }
                    }
                },
                "Policies": [
                    {
                        "SNSPublishMessagePolicy": {
                            "TopicName": {
                                "Fn::GetAtt": [
                                    "HelloWorldTopic",
                                    "TopicName"
                                ]
                            }
                        }
                    }
                ],
                "Environment": {
                    "Variables": {
                        "SNS_TOPIC_ARN": {
                            "Ref": "HelloWorldTopic"
                        }
                    }
                },
                "CodeUri": "nothing"
            }
        },
        "HelloWorldTopic": {
            "Type": "AWS::SNS::Topic",
            "Properties": {
                "Subscription": [
                    {
                        "Endpoint": "nothing",
                        "Protocol": "email"
                    }
                ]
            }
        }
    }
}

I am using the Jackson YAMLFactory to parse a YAML-file that is equivalent to this JSON. How can I parse this in a way that all the content inside "Resources" is stored in a single String? (I want to keep this as a separate YAML/JSON for further analysis)

ObjectMapper mapper = new ObjectMapper();
String resources =  mapper.readTree(new FileReader(path_to_your_json_file).at("/Resources").asText()

Or something like this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM